2

我试图在 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
4

1 回答 1

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
于 2012-12-10T18:50:58.023 回答