gui multiple menu commands problem...

i’m trying to get this scrpit to select three menu commands but i get an error
“the do_menu handler is specified more than once”
it is, but i’m not sure how to separate each one from the previous one.
is there a command that will allow me to run three consecutive degments of code to select menu commands?
the application i’m usin does not give me a dictionary when i drag it into the script editor, so does this mean i can’t script it?
thanks for the help!
–thomas

It sounds like you are confusing a handler (also called a routine, subroutine, subhandler, or command) and a call to a handler. The following code defines a handler for selecting a menu item and calls it three times. You only define the handler once and then you can call it as many times as you wish. The only caveat to it is that if you call it within the tell block of an application, make sure you add “my” before it so that the application knows to use the script’s command and not the application’s itself (which probably doesn’t exist):

Jon

Of course, the above requires that you have installed the GUI Scripting beta which was developed to script apps that don’t support native scripting on their own (a category which appears to include the app you’re trying to script).

Jon

jonn8,
thanks for the reply.
i am new to this and am a bit confused.
i can’t name the handler once, because the menu i am asked to command is different in each of the three commands.
my example is this:
as you can see, the menu functions are different, so my handler must be different for each, right?
thanks again for the help.oh and yes, i am running the beta.
–thomas

tell application “Audio Hijack Pro” to activate
open location “http://cartalk.cars.com/Radio/Show/Audio/200329/RA/all.ram
end

(* EXECUTE MENU ITEM *)
– Audio Hijack Pro, File, Open Preset

if my do_menu(“Finder”, “Finder”, “Hide Others”) is false then error number -128
if my do_menu(“Finder”, “View”, “Clean Up”) is false then error number -128

on do_menu(app_name, menu_name, menu_item)
try
– bring the target application to the front
tell application app_name
activate
end tell
tell application “System Events”
with timeout of 300 seconds – 5 minutes
tell process app_name
tell menu bar 1
click menu item menu_item of menu menu_name
end tell
end tell
end timeout
end tell
return true
on error error_message
return false
end try
end do_menu

(* EXECUTE MENU ITEM *)
– Audio Hijack Pro, Control, Start Hijacking

if my do_menu(“Finder”, “Finder”, “Hide Others”) is false then error number -128
if my do_menu(“Finder”, “View”, “Clean Up”) is false then error number -128

on do_menu(app_name, menu_name, menu_item)
try
– bring the target application to the front
tell application app_name
activate
end tell
tell application “System Events”
with timeout of 300 seconds – 5 minutes
tell process app_name
tell menu bar 1
click menu item menu_item of menu menu_name
end tell
end tell
end timeout
end tell
return true
on error error_message
return false
end try
end do_menu

(* EXECUTE MENU ITEM *)
– Audio Hijack Pro, Control, Start Recording

if my do_menu(“Finder”, “Finder”, “Hide Others”) is false then error number -128
if my do_menu(“Finder”, “View”, “Clean Up”) is false then error number -128

on do_menu(app_name, menu_name, menu_item)
try
– bring the target application to the front
tell application app_name
activate
end tell
tell application “System Events”
with timeout of 300 seconds – 5 minutes
tell process app_name
tell menu bar 1
click menu item menu_item of menu menu_name
end tell
end tell
end timeout
end tell
return true
on error error_message
return false
end try
end do_menu

Um, what? No. The whole point of the handler is that it accepts variables so you can send it commands that do things based on variable input. Just so we’re straight, the handler is the code starting with “on do_menu…” and ending with “end do_menu”. This is the part that you only put in once, usually at the top or bottom of the script. If you include this code only once, your script will compile. There is a larger problem because all you seem to be doing is calling the Finder over and over. This was example code and not meant as the code for you to actually use. Here is a script that I think does what you intended (not sure about the beginning since I don’t have Audio Hijack Pro and this may give you some problems):

It would do you good to read through the AppleScript Language Guide or an AppleScript book just to learn the basics.

Jon

After installing the GUI Scripting beta, did you make sure that “Enable access for assistive devices” is turned on in the Universal Access Preference pane? Without this, GUI Scripting won’t be able to control the menus and other interface elements.

Jon