Copy link to clipboard
Copied
I need to call a function in my script and afterwards undo, what it has done. I can do this with
app.doScript(fn)
But how do I pass an object to this asnc function? Is a skript-global array of those objects the only way?
Or is there a synchronous way (that would be preferred) to call a function and then undo, what is has done?
Copy link to clipboard
Copied
Hi @Lordrhavin, I'm assuming you're using ExtendScript because you didn't tag UXP.
Application.doScript() is synchronous. You can see here:
function main() {
$.sleep(500)
alert('main')
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Do Script');
alert('end');
You can supposedly pass arguments to the function (that's the undefined parameter above), but it seems to expect an Array of Strings, which limits things a bit. However, I use doScript all the time for managing single Undos and it seems fairly unproblematic to handle scope. You can call the app.doScript from inside a function, after all.
Does that help? I'm really not super knowledgable on this, so I hope I haven't misunderstood your question.
- Mark
Edit to more directly answer your question:
> "But how do I pass an object to this asnc function? Is a skript-global array of those objects the only way?"
You can simply use doScript to execute a function that itself has the scope you need.
Copy link to clipboard
Copied
Hi,
never used the argument for parameters in the doScript. You can do instead:
app.scriptArgs.setValue("key1", Value);
app.doScript(script);
and in "script" get the value
app.scriptArgs.get("key1);
Hope this helps
Copy link to clipboard
Copied
Hi @Stefan Rakete, thanks, I didn't know about that. In the docs it says that `value` (in .setValue) is a String. Can it accept an Object? (If not, then it would be simpler to send the argument via the app.doScript call.)
- Mark
Copy link to clipboard
Copied