Activating a menubar item in multiple languages.

Hi, I make a application which adds autosave to Logic Pro 9 and below. Written in AppleScript ObjeC It does using system events to click the save button in the file menu.

http://www.davidmckeitch.com/my-projects/mac-apps/logic-pro-autosave.html

       if FrontAppName is "Logic Pro" and pause is less than 1
try
            log "Sending Save Command via Apple Events"
            tell application "System Events" to tell process "Logic Pro"
            click menu item "Save" of menu 0 of menu bar item "File" of menu bar 0
end tell
            
            
            on error

         
         log "Sending Save command via key command fallback"
         tell application "System Events"
             keystroke "s" using command down
             
         end tell
        
            

For a while I’ve been running into the occasional user who gets the error in the log.

At first I thought it was an issue with the “Menu bar 0” part, and i tried adding a fallback to use other numbers of menu bar and such.

But today I noticed it seemed to be happening to people using other languages on there systems. I switched my system to german and yup, got the same error.

Is there anyway to handle this in applescript without repeating the script in loads of languages? Maby a number for the menu bar item?

Currently i have a fallback which sends a normal key command. However this can conflict with other things in Logic Pro and as such I would rather not use it.

Thanks for any light shed on this in advanced!

Hi,

you can retrieve the localized strings from the application bundle.
Actually the index of menu and menu bar is 1


tell application "Logic Pro"
	set saveMenuItemTitle to localized string "Save"
	set fileMenuTitle to localized string "File"
end tell

tell application "System Events" to tell process "Logic Pro"
	click menu item saveMenuItemTitle of menu 1 of menu bar item fileMenuTitle of menu bar 1
end tell

Fantastic cheers man. Will give that a try.

I switch from menu bar 1 to menu bar 0 while i was trying to figure out the problem. Both seem to work, ill put it back to 1 just to be safe though.

Currently getting the error Logic Pro got an error: Application isn’t running. (error -600)

Trying to figure out what the issues is.

For the System Events lines you have to put Logic Pro frontmost anyway


tell application "Logic Pro"
	activate
	set saveMenuItemTitle to .

Ah my app is sandboxed i think its an issue with that. Will report back.

Try the sequence

tell application "Logic Pro"
launch
activate
.

or if your app is not allowed to send Apple Events to Logic Pro,
launch Logic with NSWorkspace in AppleScriptObjC

Seems to be solved. I had sandboxed my app to try and get it into the Mac App store but Apple were not happy with me using apple events in this way so it never got in.

All I had to do was add an entitlement so that my app could talk to the Logic Pro.app.

com.apple.security.temporary-exception.apple-events

then under that I added

com.apple.logic.pro

…which I’m sure would be another reason for apple not allowing my app in the app store but oh well. Selling the old fashioned way seems to be working out well.

Seems to work under the english language now will give it a test in some other languages. Thanks Stephan! Been struggling with that for a while.

Works under other languages :).