
我已經設定了盒子簡單分享應用程式在登入時啟動,但應用程式在功能表列中載入其圖示後立即啟動其首選項窗格。將其設定為以“隱藏”模式啟動 系統偏好設定 > 使用者和群組 > 登入項不會改變這種行為。
我嘗試創建一個 AppleScript,另存為應用程序,以啟動盒子簡單分享應用程式在登入並隱藏首選項窗格,但它無法按預期工作。
set tApp to "Box SimpleShare"
tell application tApp to launch
tell application "System Events"
set visible of process "Box SimpleShare" to false
end tell
這會啟動應用程序,但不會關閉盒子簡單分享首選項窗格。執行此操作的正確程式碼是什麼?
答案1
Box 的首選項視窗是一個特別持久的視窗 - 它不僅堅持在每次啟動應用程式時顯示,而且如果在應用程式完成其初始化序列之前關閉它,它還會重新打開!然而,使用一些 GUI 腳本,它是有可能擺脫它。以下程式碼將啟動應用程序,等待首選項視窗彈出並在短暫延遲後關閉它(以便它可以完成其初始化序列):
property timeOutMax : 5
property timeOutStep : 1
property boxLoadDelay : 2
set boxApp to "Box SimpleShare"
tell application boxApp to launch
set timeOutCounter to 0
tell application "System Events"
tell process boxApp
repeat while (window 1 of it exists) is false and timeOutCounter is less than timeOutMax
delay timeOutStep
set timeOutCounter to timeOutCounter + timeOutStep
end repeat
if window 1 of it exists then
delay boxLoadDelay
click (button 1 of window 1 of it)
end if
end tell
end tell
如果視窗在您的系統上重新打開,請設定更高的值boxLoadDelay
。另外,如果腳本在應用程式載入之前逾時,請調整 的值timeOutMax
(timeOutStep
如果必須選擇更高的超時閾值,則可能需要調整 的值)。