AppleScript GUI scripting problem

Hi All,

I’ve created a script that will automatically open new document in Indesign CS2. But when i run the script i’m getting system events error as “NSReceiverEvaluationScriptError: 4”. I tried following the instruction given in forums but still couldn’t figure out. Below is the script i wrote. Can any one tell where and what i’m missing.

tell application “Adobe InDesign CS2” to activate
tell application “System Events”
tell process “Adobe InDesign CS2”
tell menu bar 1
tell menu bar item “File”
tell menu “File”
tell menu item “New”
tell menu “New”
click menu item “Document”
end tell
end tell
end tell
end tell
end tell
click button “Ok” of window 1
end tell
end tell

This is the submenu of menu New. This might be the problem cos the below script works for for which i’m clicking the menu not sub menu

tell application “Adobe InDesign CS2” to activate
tell application “System Events”
tell application process “Adobe InDesign CS2”
tell menu bar 1
tell menu bar item “Help”
tell menu “Help”
click menu item “Welcome Screen…”
end tell
end tell
end tell
end tell
end tell
My Mac version is 10.4.10
Any help would be appreciated.

-Jacintha

Hi Jac

I’m unsure of your reasons for making a new document using GUI scripting.
but heres a way of doing it with out.

tell application "Adobe InDesign CS3" to make new document

if you need to create at a certain size or name it etc. then you need to add properties

tell application "Adobe InDesign CS3" to make new document with properties {name:"jacintha"}

Checkout the document preferences and the view preferences in the indesign dictionary for tips on how to set up a new document.

regardless of the sense for using GUI scripting instead of the application’s AppleScript dictionary,
make sure that “Enable access for assistive devices” is checked in System Preferences → Universal Access
to avoid “NSReceiverEvaluationScriptError: 4”

Hi pidge, actually i want to use the “plugin” Menu which i have in my Indesign . The plugin has its sub menu which i need to click. I tried working on clicking “New” cos it has sub-menu named “Document”. But i’m not able to do this using GUI scripting.

Stefan, in my maching Enable access for assistive devices is enabled. but still it is not working. any other ideas?

jacintha:

GUI Scripting is unpleasant to write at best and broken at the worst (and it’s usually at its worst!) I personally avoid it like the plague (and I’ve been plague free for many years now!:D) Also, realize that despite how powerful AS can be, there are some things it can’t do (or it can’t do safely and efficiently.).

Just something to think about.

Jim Neumann
BLUEFROG

What plugin is it?

MathMagic Plugin

Custom submenus are troublesome with UI scripting, especially those that are context-sensitive or dynamic. The printer choices popup from Adobe InDesign print dialogs comes to mind (cringeshudder).

I’m assuming you’ve located the menu using something like Prefab’s UI Browser and are addressing it properly. That being said, I can’t repeat this enough for UI scripting (which I’ve had to do my fair share of) that “delay” is your friend. As little as “delay 0.2” in between key steps in the selection or activation process can really smooth things out.

When my UI scripts start to go awry, or act inconsistantly from run-to-run, I usually start with a “delay 2.0” between each selection/call. If it solves the problem, I run the delay down to 1, then 0.5, then 0.2. If it keeps working, then I start removing the delays until it breaks again, etc.

This long-winded methodoly speech is really to say, try a “delay 2” just before clicking the OK button in the script you provided. :wink:

Hey,
The error you’re receiving is from a bad menu item address; “Document” should be “Document…”. I typically don’t GUI script, and I can’t tell you why the code fails to invoke the window, even with this correction, but it does. You’ll receive another error on line “click button “Ok” of window 1”, as your click isn’t going to the intended window”which never opened”, but to ID’s palettes.


tell application "Adobe InDesign CS2" to activate
    tell application "System Events"
        tell process "Adobe InDesign CS2"
            tell menu bar 1
                    tell menu "File"
                        tell menu item "New"
                            tell menu "New"
                                click menu item "Document..." --silently fails
                            end tell
                        end tell
                end tell
            end tell
           --click button "Ok" of window 1 --you're addressing palettes
        end tell
    end tell

@Marc Anthony: Is it a true ellipsis “.” or three periods?

@jacintha: See what I mean about being unpleasant to write! :smiley:

They are just periods.