0

我想让我的窗口最前面-1。我有一个应用程序,当我离开计算机超过 30 分钟时,它会激活 Safari 以每两分钟运行一次 JavaScript。但是,当脚本完成后,我希望 Safari 最前面 -1。因此,与我离开计算机时相同的窗口位于最前面。

我知道我可以隐藏或最小化我的 Safari 窗口,但这不是我想要的 :-) 有什么想法吗?

4

1 回答 1

0

与其让 Safari 排在最前面 - 1,您可以做的是将之前的应用程序放在最前面。由于 Safari 当前位于最前面,这将使 Safari 最前面减去 1。

这是一个应用程序,它会记住当前活动应用程序的名称,激活 Safari,然后返回到上一个活动应用程序。

on idle
    tell application "System Events"
        -- remember the current active app
        set currentActiveApp to first process where it is frontmost
        set activeAppName to name of currentActiveApp

        display notification activeAppName

        tell application "Safari"
            --do stuff with Safari that makes it frontmost
            activate
        end tell

        --make sure we have had time to switch to Safari
        repeat while (currentActiveApp is frontmost)
            delay 0.4
        end repeat
        --delay so that we can see we are in Safari
        delay 2

        --return to previous application
        display notification "Returning to " & activeAppName
        set frontmost of currentActiveApp to true
        delay 2

    end tell

    --do it all over in ten seconds
    return 10
end idle
于 2016-02-04T18:25:14.430 回答