塞拉的腳本:
set doNotShowSplashScreen to (do shell script "defaults read com.apple.VoiceOverTraining doNotShowSplashScreen") as integer as boolean
on error
set doNotShowSplashScreen to false
end try
if doNotShowSplashScreen then
do shell script "/System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter"
else
do shell script "defaults write com.apple.VoiceOverTraining doNotShowSplashScreen -bool true && /System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter"
end if
其他 macos 的腳本:
tell application id "com.apple.systemevents" to key code 96 using command down
uj5u.com熱心網友回復:
有一種獲取系統版本的本機方式
set systemVersion to system version of (system info)
if systemVersion starts with "10.12" then
try
set doNotShowSplashScreen to (do shell script "defaults read com.apple.VoiceOverTraining doNotShowSplashScreen") as integer as boolean
on error
set doNotShowSplashScreen to false
end try
if doNotShowSplashScreen then
do shell script "/System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter"
else
do shell script "defaults write com.apple.VoiceOverTraining doNotShowSplashScreen -bool true && /System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter"
end if
else
tell application id "com.apple.systemevents" to key code 96 using command down
end if
uj5u.com熱心網友回復:
您的兩個腳本之間的區別比其內容暗示的要稍微重要一些。首先,他們做不同的事情:第一個(如果它沒有丟失它的初始try塊開啟器)將doNotShowSplashScreenVoiceOver的標志設定為true,然后啟動 VoiceOver(即打開它);第二個啟動 VoiceOver(將其打開)如果它不是活動的,并且退出 VoiceOver(將其關閉)如果它是。
此外,do shell script在 Mac OS X 10.1 中引入。同時,系統事件直到 Mac OS X 10.6.3 才被引入。因此,第二個腳本在 Sierra 中執行得很好,但不能在 Snow Leopard 之前的任何腳本中執行。第一個腳本應該在 Puma 之后的版本中正常執行。
我建議考慮測驗系統版本的相關性,如果您確實需要,您的腳本之間的區別是否真正反映了這種相關性。
@user3439894 幫助您指出了system version of (system info). AppleScript 允許對版本字串進行數字比較,如下所示:
set os_sevs_available to true
considering numeric strings
if "10.6.3" > (system info)'s ?
system version then set ?
os_sevs_available to false
end considering
或者,等效地:
considering numeric strings
set os_sevs_available to (system info)'s system version ≥ "10.6.3"
end considering
如果您完成了第一個腳本的邏輯,很明顯在任何情況下的最終結果都是 execute do shell script "/System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter",即。打開 VoiceOver。略少明顯的是,通過腳本的最后,doNotShowSplashScreen對VoiceOver的標志將永遠是true不管它的初始狀態。所以:
第一個觀察結果突出了我上面提到的兩個腳本功能之間的差異,因為系統事件命令將切換 VoiceOver。這可以像這樣糾正:
if os_sevs_available then if application id "com.apple.VoiceOver" is running then return tell application id "com.apple.systemevents" to key code 96 using command down end if第二個觀察意味著沒有一點閱讀的價值
doNotShowSplashScreen在你的“塞拉”劇本的開始標志,這樣你就可以取出整個try干脆塊,并且放棄了if...then...else條件測驗,以及。這允許您的第一個腳本簡化為:do shell script "defaults write com.apple.VoiceOverTraining doNotShowSplashScreen -bool true; /System/Library/CoreServices/VoiceOver.app/Contents/MacOS/VoiceOverStarter"請注意,這是一個包含換行符的字串,非常好
我會讓你來確定你是否真的需要這兩個腳本。在我看來,它們似乎可以在 10.6.3 之后的任何系統版本上運行,并且由于它們之間現在唯一的功能區別是defaults鍵/值對的撰寫,因此我很想堅持使用單個呼叫以do shell script及清除一切。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/373511.html
下一篇:嘗試在MacM1上運行我的xamarin.formsios應用程式。當我打開任何包含帶有部分標題的TableView的頁面時崩潰
