AppleScript管理Windows
问题描述:
我想让我的窗口到最前面-1。我有一个应用程序激活Safari,当我离开计算机超过30分钟时,每两分钟运行一次JavaScript。但是,当脚本完成时,我希望Safari能走到最前面-1。这样,同一个窗口就像我离开电脑时的最前面一样。AppleScript管理Windows
我知道我可以隐藏或最小化我的Safari窗口,但这不是我想要的:-)任何想法?
答
与其让Safari最前面减1,你可以做的是让以前的应用程序成为最前面的东西。由于Safari浏览器是目前最前方,这将使Safari浏览器最前面的减1
这里是会记住当前活动的应用程序的名称,启动Safari浏览器,然后返回到先前的活跃APP应用程序。
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
当Safari是活动应用程序时,是否需要运行JavaScript?大多数命令也可以在后台运行。 – vadian