如何在没有13秒延迟的情况下立即执行此ApplesScript?

时间:2012-12-10 12:57:40

标签: macos applescript shortcut automator logmein

我试图在OSX Mountain Lion上创建一个快捷方式,使用LogMeIn应用程序“共享文件”,因为不存在。我打开了Automator并在“看我做”下创建了一个应用程序。我点击了记录 导航到菜单栏并单击“LogMeIn”>“共享文件...”,然后在该对话框中单击“共享文件”并停止录制。然后我将命令复制到Automator中并将它们粘贴到AppleScript编辑器中,希望改变一些事情以使其更快地执行。我在Automator中选择了10倍的速度,从我做快捷方式起,它仍然需要大约13秒。如果有人知道如何更改此AppleScript以使其即时,请随时更改它。

任何帮助都将不胜感激。

由于

-- 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

1 个答案:

答案 0 :(得分:0)

真的很酷。我不知道你可以在AppleScript编辑器中复制/粘贴那些“看我做”命令。我想我会找到它的用途。

无论如何,你可能无法使你的代码“即时”,因为ui脚本只是这样做。但是,如果我将您的代码编写为常规的AppleScript,那就是它的样子。尝试一下,也许会有所帮助。我无法测试它,因为我没有该应用程序。祝你好运。

注意:我将“共享文件...”设为“共享文件”和省略号字符(选项分号)。如果您遇到问题,请尝试将省略号更改为3个周期。

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