I have a .jsx file for Photoshop that gives back the opacity value of the actual brush that is used. Right now it saves this value to the clipboard:
opacity.jsx:
#target photoshop
function BrushOpacityGet()
{
var ref = new ActionReference();
ref.putEnumerated(charIDToTypeID("capp"),
charIDToTypeID("Ordn"),
charIDToTypeID("Trgt")
);
var AD = executeActionGet(ref);
AD = AD.getObjectValue(stringIDToTypeID("currentToolOptions"));
return(AD.getInteger(stringIDToTypeID("opacity")));
}
op = BrushOpacityGet();
ops = app.system("osascript -e 'set the clipboard to \"" + op +"\"'");
now I want to save this value in a KM Variable instead of clipboard, I already tried this:
ops = app.system("osascript -e 'tell application "Keyboard Maestro Engine" to setvariable "ps_opacity" to "op"'");
But that gives me back "Error 25: Expected: )."
I also tried this:
ops = app.system("osascript -e 'tell application \"" + Keyboard Maestro Engine +"\" to setvariable \"" + ps_opacity+"\"' to \"" + op +"\"'");
I think you need to escape the double quotes in your string: ops = app.system("osascript -e 'tell application \"Keyboard Maestro Engine\" to setvariable \"ps_opacity\" to \"op\"'");
I tested it on the complete line but that will (I should have expected that ) escape all the quotes, including the first and the last. So maybe only put in the string?
haha, that would have been to good to be true I will definitely try a bit more with that tool. But I guess it seems I need to learn a bit more about that.
One last question, I also want to trigger a KM macro in that jsx file, so my last line was:
Mmmm, I couldn't get this out of my head. Let alone stand that I had no answer
So... I did some experimenting.
I took your osascript command, put in the UID of one of my macros and ran it in Terminal.
The result: syntax error: Expected end of line but found identifier. (-2741)
Pasting only the AppleScript in Script Debugger resulted in 2 errors: expecting an 'end of line' and an unexpected 'end of script'. So I separated lines and added a ' end tell' command.
To 'translated' this to osascript you can use multiple -e switches. So your line should read:
Hey @Reheer, sorry for the delay! I just tested and it works! The strange thing is, in the meantime I solved it by running a Alfred Workflow that triggers a Keyboard Maestro macro, and it worked with this here:
oxo = app.system("osascript -e 'tell application id \"com.runningwithcrayons.Alfred\" to run trigger \"ps\" in workflow \"jsx\"'");
Don´t know why, but I will use your solution now - Thanks for your help!