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

[CS5 JS] Closing a dialog box with a script

Participant ,
Oct 15, 2011 Oct 15, 2011

I've got a little project that uses a 3rd party plug-in to InDesign CS5 Mac, and the plug-in isn't scriptable. I've written a little script that, after it does a bunch of processing, runs the following:

try {

    var myMenuAction1 = app.menuActions.item("Create Job...");

    myMenuAction1.invoke();       

}

catch (myError) {};

This snippet opens the "Create Job.." dialog box of the plug-in. Now I just need to be able to close the dialog, which would be done with the keyboard by hitting OK, because the "Create" button that starts the process and closes the dialog is the default button, so hitting return activates it.

Is there any way to pass a return via scripting so I can get this box to close automatically?

Thx for any advice!

TOPICS
Scripting
1.4K
Translate
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
LEGEND ,
Oct 15, 2011 Oct 15, 2011

Keith: No. The .invoke() action won't return until the dialog box is done, the script will be stuck.

You can ask the operating system to send an ENTER key though. What OS?

It's kind to be kludgey though. Consider asking the vendor for scripting support.

Translate
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
Participant ,
Oct 15, 2011 Oct 15, 2011

John, kludgey is OK in this case. Using Mac OSX. Can you point me in the right direction? Thx.

~ Keith

Translate
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
LEGEND ,
Oct 15, 2011 Oct 15, 2011

You must go to System Preferences > Universal Access and check "enable access for assistive devices" and then you can do something like:

app.doScript(

'delay 2\ntell application "System Events" to tell process "Adobe InDesign CS5" to keystroke return',

ScriptLanguage.APPLESCRIPT_LANGUAGE);

Adjust the delay to taste. I hope that'll work asynchronously, otherwise you might need to find some better way to do it. A bad way would be to "do shell script" execution of "sleep 2; osascript -e 'tell app...' &" with the ampersand at the end to run the whole thing in the background. I'm sure someone can come up w/ a better way if that's necessary.

Translate
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
Participant ,
Oct 15, 2011 Oct 15, 2011

John, this doesn't seem to work asynchronously. It waits with the dialog box open, then after I click the button to leave the dialog the return is "typed" after the delay.

~ Keith

Translate
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
LEGEND ,
Oct 15, 2011 Oct 15, 2011

Did you try running the applescript before you run the .invoke()?

Translate
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
Participant ,
Oct 15, 2011 Oct 15, 2011

Well, that makes sense. That works perfect! Of course the AppleScript needs to run before the .invoke().

Thanks so much for your help!

~ Keith

Translate
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
Guru ,
Oct 16, 2011 Oct 16, 2011
LATEST

You must go to System Preferences > Universal Access and check "enable access for assistive devices" and then you can do something like:

John, for system events to execute GUI items this is true… but for the case of keystrokes its not necessary. You should be able to access these without the need to change system prefs…

Translate
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