[CS5 JS] Closing a dialog box with a script
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
John, kludgey is OK in this case. Using Mac OSX. Can you point me in the right direction? Thx.
~ Keith
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Did you try running the applescript before you run the .invoke()?
Copy link to clipboard
Copied
Well, that makes sense. That works perfect! Of course the AppleScript needs to run before the .invoke().
Thanks so much for your help!
~ Keith
Copy link to clipboard
Copied
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…

