Applescript“跳”到指定的应用程序并回到上一个应用程序?

时间:2013-12-15 23:55:27

标签: macos applescript

我喜欢使用此脚本来显示需要经常访问的有用应用程序。我希望这个脚本在运行时返回到上一个应用程序,而不是在可见时隐藏它。什么代码需要更改,以便当“邮件”可见时,它将跳转到以前打开的应用程序?

    set appName to "Mail"

    set appID to bundle identifier of (info for (path to application appName))
    tell application "System Events"
        if not (exists process appName) then
            tell application appID to activate
        else
            if frontmost of process appName then
                set visible of process appName to false
            else
                set frontmost of process appName to true
            end if
        end if
    end tell

1 个答案:

答案 0 :(得分:0)

我不知道如何让第二个最前面的应用程序除了这样的黑客之外:

tell application "System Events"
    set p to process 1 where frontmost is true
    set visible of p to false
    delay 0.01
    set a to process 1 where frontmost is true
    delay 0.01
    set frontmost of p to true
    a
end tell
tell application "System Events"
    keystroke tab using command down
    delay 0.01
    set a to path to frontmost application as text
    delay 0.01
    keystroke tab using command down
    a
end tell

您可以隐藏然后显示应用程序:

if (path to frontmost application) is (path to application "Mail") then
    tell application "System Events"
        set visible of process "Mail" to false
        delay 0.01
        set visible of process "Mail" to true
    end tell
else
    activate application "Mail"
end if