AppleScript 程式設計/高階程式碼列表/隱藏應用程式
外觀
有時,你的指令碼需要執行一些沒有定義 AppleEvent 來完成的任務。在這種情況下,你可以透過圖形使用者介面 (GUI) 來編寫指令碼,使用一種稱為 **GUI 指令碼** 的技術。
例如,要隱藏最前面的應用程式,你可以執行以下操作
tell application "System Events" to keystroke "h" using command down
然後,要隱藏所有後臺程式
tell application "System Events" to keystroke "h" using {command down, option down}
但是,當你想隱藏一個 **處於後臺的特定應用程式** 時,就會變得更加棘手
tell application "System Events" to tell process "Safari" to set visible to false
Safari 這裡只是一個例子。
我使用 iKey 在 Adium 失效後執行此指令碼
tell application "Adium"
set vCounter to count every window
if vCounter < 2 then tell application "System Events" to tell process "Adium" to set visible to false
end tell
簡而言之,如果只有一個視窗(例如,好友列表)開啟,它會隱藏 Adium。