What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Scripting Simple script using ChatGPT to reset ruler settings


spam24

Member
Messages
12
Likes
0
I'm trying to write a simple script using ChatGPT to reset ruler settings
Nothing works :(
Why this script doesn't work in Photoshop CS6 (old version) ?
Regards, Arek
--------------------------------------------------------
// Reset Rulers to Starting Position (0, 0)

// Set ruler units to pixels
app.preferences.rulerUnits = Units.PIXELS;

// Set the active document
var doc = app.activeDocument;

// Set the origin point of the ruler to (0,0)
doc.rulerOrigin = [0, 0];
 
I'm not at all familiar with ChatGPT because I do not use it, so please educate me. Did you not ask it why the script would not work? Shouldn't it know why the script is not working?
 
Screen Shot 2024-04-16 at 12.32.54 PM.png
I was asking a genuine question because I really do NOT know! I assumed it should know but I'm obviously wrong!
 
Hello,

Thank you for your response. I appreciate your willingness to assist.

ChatGPT is an AI language model developed by OpenAI, and it's often used for various text-related tasks, including scripting. While it's quite powerful, it doesn't possess the ability to actively debug scripts or provide specific troubleshooting for software like Photoshop CS6.

My initial inquiry was indeed about why the script wasn't functioning as expected in Photoshop CS6. I'm hoping to receive insights or tips from the community here, as some members might have experience with similar issues or know of workarounds for older software versions.

If you have any suggestions or advice on how to troubleshoot scripts in Photoshop CS6, I'd greatly appreciate it.

Thank you again for your time and assistance.

Best regards, Arek
 
ChatGPT is an AI language model developed by OpenAI
Yes, I knew this. But thanks for the reminder.

and it's often used for various text-related tasks, including scripting. While it's quite powerful, it doesn't possess the ability to actively debug scripts or provide specific troubleshooting for software like Photoshop CS6.
I find that interesting. While it does have the ability to write a script for a specific software like Ps CS6, one would think it would posses the ability to also debug and troubleshoot the script. Thanks I really appreciate the reply!!

If you have any suggestions or advice on how to troubleshoot scripts in Photoshop CS6, I'd greatly appreciate it.
Unfortunately, I do not know anything about troubleshooting scripts. For what I do professionally, I don't have much use for repetitive tasks beyond what can usually be done with an action.

Hopefully another member will have answers for you.
 
So about my question, is it possible to reset the ruler using JavaScript?
I mean using a script instead of doing it manually by double-clicking the right left corner.
Thank you again for your time and assistance.

Best regards, Arek
 
Thank you very much for the tip, this is exactly what I'm looking for
Regards, Arek
 
I'm trying to write a simple script using ChatGPT to reset ruler settings
Nothing works :(

Generative pre-trained AI software is only as good as the sample/training data ingested... And sometimes it just makes stuff up to be "helpful"! :]

It's early days for these tools and they often produce garbage code... Or code that is 90% accurate but the remaining 10% is rubbish and therefore makes the entire code useless unless you know how to script and find the errors and work around them.

Take for example the following line from your code:

JavaScript:
doc.rulerOrigin = [0, 0];

There is no such thing as rulerOrigin in the Photoshop DOM:

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document.html
 
Last edited:
Some simple fixes are needed...


Thanks for linking to my GitHub!

The original code came from an Adobe Employee, Tom Ruark, it is esoteric and complex, making use of AM code (Action Manager), not DOM code (Document Object Model).

https://community.adobe.com/t5/phot...ler-origin-location-in-photoshop/m-p/10844115

https://community.adobe.com/t5/phot...ot-ruler-origin-quot-by-script/idi-p/12248809

https://community.adobe.com/t5/photoshop-ecosystem-discussions/rulers-and-scripting/m-p/13351557

If one doesn't need a GUI, and just wishes to reset the ruler origin to zero:

JavaScript:
/* https://feedback.photoshop.com/conversations/photoshop/photoshop-ability-to-ruler-origin-by-script/5f5f45bb4b561a3d425c7b32 */

// Version 2016.11.18
// Show how to get and set the ruler origin point for the current document
// Values are in pixels shifted 16 bits
// some constants to make it more readable

const classProperty = app.stringIDToTypeID("property");
const krulerOriginHStr = app.stringIDToTypeID("rulerOriginH");
const krulerOriginVStr = app.stringIDToTypeID("rulerOriginV");
const classDocument = app.stringIDToTypeID("document");
const typeOrdinal = app.stringIDToTypeID("ordinal");
const enumTarget = app.stringIDToTypeID("targetEnum");
const typeNULL = app.stringIDToTypeID("null");
const keyTo = app.stringIDToTypeID("to");
const eventSet = app.stringIDToTypeID("set");

// get the current values
GetRulerOrigin().toSource();

// set them to zero, negative numbers work as well
SetRulerOrigin(0, 0);

function GetRulerOrigin() {
    var ro = {};

    ro.horizontal = GetInfo(classDocument, krulerOriginHStr) >> 16;
    ro.vertical = GetInfo(classDocument, krulerOriginVStr) >> 16;

    return ro;
}

function SetRulerOrigin(horiz, vert) {
    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putProperty(classProperty, krulerOriginHStr);
    ref.putEnumerated(classDocument, typeOrdinal, enumTarget);
    desc.putReference(typeNULL, ref);
    desc.putInteger(keyTo, horiz << 16);
    executeAction(eventSet, desc, DialogModes.NO);

    var desc = new ActionDescriptor();
    var ref = new ActionReference();
    ref.putProperty(classProperty, krulerOriginVStr);
    ref.putEnumerated(classDocument, typeOrdinal, enumTarget);
    desc.putReference(typeNULL, ref);
    desc.putInteger(keyTo, vert << 16);
    executeAction(eventSet, desc, DialogModes.NO);
}

///////////////////////////////////////////////////////////////////////////////
// Function: GetInfo
// Usage: Get information from Photoshop
// Input: desiredClass, classApplication, classLayer, etc.
//        desiredKey, optional specific key to get instead of everything
//                    this is recommended as all keys is an expensive call
// Return: ActionDescriptor or single value depending on what is asked for
///////////////////////////////////////////////////////////////////////////////
function GetInfo(desiredClass, desiredKey) {
    var reference = new ActionReference();
    if (typeof desiredKey != "undefined") {
        reference.putProperty(stringIDToTypeID("property"), desiredKey);
    }
    reference.putEnumerated(desiredClass, stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
    var desc = executeActionGet(reference);
    if (typeof desiredKey != "undefined") {
        return GetItemFromDescriptor(desc, desiredKey);
    }
    return desc;
}

///////////////////////////////////////////////////////////////////////////////
// Function: GetItemFromDescriptor
// Usage: Get a specific key from an ActionDescriptor
// Input: desc (ActionDescriptor), valid ActionDescriptor to pull info from
//        desiredKey (Number), key in question, use charIDToTypeID() or
//                             stringIDToTypeID()
// Return: ActionDescriptor or single value depending on what is asked for
///////////////////////////////////////////////////////////////////////////////
function GetItemFromDescriptor(desc, desiredKey) {
    if (desc.hasKey(desiredKey)) {
        var typeID = desc.getType(desiredKey);
        switch (typeID) {
            case DescValueType.BOOLEANTYPE:
                return desc.getBoolean(desiredKey);
                break;
            case DescValueType.STRINGTYPE:
                return desc.getString(desiredKey);
                break;
            case DescValueType.DOUBLETYPE:
                return desc.getDouble(desiredKey);
                break;
            case DescValueType.INTEGERTYPE:
                return desc.getInteger(desiredKey);
                break;
            case DescValueType.LARGEINTEGERTYPE:
                return desc.getLargeInteger(desiredKey);
                break;
            case DescValueType.OBJECTTYPE:
                return desc.getObjectValue(desiredKey);
                break;
            case DescValueType.UNITDOUBLE:
                var newT = desc.getUnitDoubleType(desiredKey);
                var newV = desc.getUnitDoubleValue(desiredKey);
                return new UnitValue(newV, newT);
                break;
            case DescValueType.ENUMERATEDTYPE:
                return desc.getEnumerationValue(desiredKey);
                break;
            case DescValueType.CLASSTYPE:
                return desc.getClass(desiredKey);
                break;
            case DescValueType.ALIASTYPE:
                return desc.getPath(desiredKey);
                break;
            case DescValueType.RAWTYPE:
                var tempStr = desc.getData(desiredKey);
                var rawData = new Array();
                for (var tempi = 0; tempi < tempStr.length; tempi++) {
                    rawData[tempi] = tempStr.charCodeAt(tempi);
                }
                return rawData;
                break;
            case DescValueType.REFERENCETYPE:
                return desc.getReference(desiredKey);
                break;
            case DescValueType.LISTTYPE:
                return desc.getList(desiredKey);
                break;
            default:
                return;
        }
    }
    return;
}
 
Last edited:
Generative pre-trained AI software is only as good as the sample/training data ingested... And sometimes it just makes stuff up to be "helpful"! :]

It's early days for these tools and they often produce garbage code... Or code that is 90% accurate but the remaining 10% is rubbish and therefore makes the entire code useless unless you know how to script and find the errors and work around them.

Take for example the following line from your code:

JavaScript:
doc.rulerOrigin = [0, 0];

There is no such thing as rulerOrigin in the Photoshop DOM:

https://theiviaxx.github.io/photoshop-docs/Photoshop/Document.html
--------------
Yes, this is the best example of what the situation is like.
I don't read the code with understanding because I don't know anything about it, I deal with other things.
But I love scripts that help with the drudgery of everyday work.
 

Back
Top