• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

doScript is async. How do I pass an object?

Participant ,
Apr 08, 2024 Apr 08, 2024

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?

TOPICS
How to , Scripting

Views

212

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2024 Apr 08, 2024

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 08, 2024 Apr 08, 2024

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2024 Apr 08, 2024

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 08, 2024 Apr 08, 2024

Copy link to clipboard

Copied

quote

[...]
But how do I pass an object to this asnc function?

[...]


By @Lordrhavin

 

What kind of object?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines