如果您的應用程序編寫腳本,並允許設置一個窗口的指數,你可以做以下(基於How do I make a Safari window active using AppleScript (elegantly)?答案)
to raiseWindow of theApplicationName for theName
tell the application named theApplicationName
activate
set theWindow to the first item of ¬
(get the windows whose name is theName)
if index of theWindow is not 1 then
set index to 1
set visible to false
set visible to true
end if
end tell
end raiseWindow
知名度的觸發是必要處理伴隨着切換應用程序出現的一些奇怪現象。如果您不切換可見性,那麼當您切換離開並返回到應用程序時,該窗口不會成爲第一個。不幸的是,這種切換將窗口縮小到碼頭,然後恢復它,這是一個非常戲劇性的UI中斷。
這裏的另一種方式,我發現要處理的怪事:
to raiseWindow2 of theApplicationName for theName
tell the application named theApplicationName
activate
set theWindow to the first item of ¬
(get the windows whose name is theName)
if the index of theWindow is not 1 then
set the index of theWindow to 2
tell application "System Events" to ¬
tell application process theApplicationName to ¬
keystroke "`" using command down
end if
end tell
end raiseWindow2
美麗!它至少可以爲我的應用程序預期。謝謝。 – KingBOB
在OS X Yosemite上,此腳本的執行給了我錯誤(不能只複製粘貼,因爲我有本地化的錯誤消息):系統事件出錯:無法配置進程「appIT」爲true。自2012年以來有所改變? –
@AntonKoval'執行窗口1的動作「AXRaise」在優勝美地爲我工作 – ling