2

I was trying to make a shortcut on OSX Mountain Lion to "Share a file" with the LogMeIn Application as one does not exist. I opened Automator and created an Application under "watch me do". I clicked record and navigated to the menu bar and clicked on "LogMeIn">"Share a file..." and clicked "Share a file" in that dialog box and stopped recording. I then copied the commands in Automator and pasted them in AppleScript editor, hoping to change a few things to make it execute faster. I chose 10x for the speed in Automator and it still takes about 13 seconds from the time I do the shortcut. If anyone knows how to change this AppleScript to make it instant, please feel free to change it.

Any help would be appreciated.

Thanks

-- Click the “<fill in title>” menu.
set timeoutSeconds to 2.0
set uiScript to "click menu bar item 1 of menu bar 1 of application process \"LogMeIn Menubar\""
my doWithTimeout(uiScript, timeoutSeconds)

-- Share a file...
set timeoutSeconds to 2.0
set uiScript to "click menu item \"Share a file...\" of menu 1 of menu bar item 1 of menu bar 1 of application process \"LogMeIn Menubar\""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “Share a file...” button.
set timeoutSeconds to 2.0
set uiScript to "click UI Element \"Share a file...\" of group 1 of window \"LogMeIn\" of application process \"LogMeIn\""
my doWithTimeout(uiScript, timeoutSeconds)

on doWithTimeout(uiScript, timeoutSeconds)
    set endDate to (current date) + timeoutSeconds
    repeat
        try
            run script "tell application \"System Events\"
" & uiScript & "
end tell"
            exit repeat
        on error errorMessage
            if ((current date) > endDate) then
                error "Can not " & uiScript
            end if
        end try
    end repeat
end doWithTimeout
adayzdone
  • 11,120
  • 2
  • 20
  • 37
Elias
  • 91
  • 1
  • 8

1 Answers1

0

That's really cool. I didn't know you could copy/paste those "watch me do" commands in AppleScript Editor. I think I'll find a use for that.

Anyway you may not be able to make your code "instant" because ui scripting just does that. However if I was writing your code as a regular applescript, here's what it would look like. Try it, maybe it will help. I can't test it because I do not have that application. Good luck.

NOTE: I made "Share a file…" as "Share a file" and an ellipsis character (option-semicolon). If you have problems try changing the ellipsis to 3 periods.

set timeoutSeconds to 2.0

tell application "LogMeIn Menubar" to activate
tell application "System Events"
    tell process "LogMeIn Menubar"
        click menu bar item 1 of menu bar 1

        -- delay until it opens
        set startTime to current date
        repeat until exists menu 1 of menu bar item 1 of menu bar 1
            delay 0.2
            if (current date) - startTime is greater than timeoutSeconds then
                error "Waited too long for menu 1 of menu bar item 1 of menu bar 1"
            end if
        end repeat

        click menu item "Share a file…" of menu 1 of menu bar item 1 of menu bar 1

        -- delay until it opens
        set startTime to current date
        repeat until exists group 1 of window "LogMeIn"
            delay 0.2
            if (current date) - startTime is greater than timeoutSeconds then
                error "Waited too long for group 1 of window \"LogMeIn\""
            end if
        end repeat

        click UI element "Share a file…" of group 1 of window "LogMeIn"
    end tell
end tell
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • Thanks, it sped up the execution significantly. Typing the three periods made it run. It does not select the second "Share a file..." once the application is launched and gives me this error message: AppleScript Error Waited too long for group 1 of window "LogMeIn". Any ideas? Thanks again for the help. – Elias Dec 17 '12 at 03:05
  • Well you can try 2 things. 1) set timeoutSeconds to a bigger value, which will make the wait time longer or 2) remove the entire delay section (section with repeat until exists group 1 of window "LogMeIn") and see if it works without it. – regulus6633 Dec 17 '12 at 09:55
  • I removed the part that you suggested and it works with out the error message. It does not open the "Choose File" contextual menu but I timed it and it was only 3 seconds faster than the "watch Me Do" generated script. I don't know if it is possible to speed this up. Do you know of an app that I could click on UI items, save them as bookmarks and turn them in to shortcuts? – Elias Dec 18 '12 at 12:08