我正在嘗試使用 Applescript訪問隱私->輔助功能選項卡。誰能幫我?
我需要顯示該部分中所有程式的串列:
- 無障礙
- 相機
- 麥克風
- 相片
- 等等...
請求本身和終端中的輸出使用osascript -e.
有必要排除與 GUI 的互動。這是我設法找到的
osascript -e 'tell application "System Events" to get the name of every login item'
我需要為輔助功能找到相同的解決方案嗎?并獲得與下面螢屏截圖相同的結果。
主要目標是
- 本地獲取Security & Privacy 中包含的資訊 2) 通過 SSH 連接到 mac OS 并獲取Security & Privacy 中包含的資訊。如果這是不可能的,那么如何使用單個 Apple 腳本顯示資訊。
uj5u.com熱心網友回復:
您應該按照以下方式轉義嵌套引號。并且,激活系統偏好設定。
osascript -e "
tell application id \"com.apple.systempreferences\"
activate
reveal anchor named \"Privacy_Accessibility\" in pane id \"com.apple.preference.security\"
end tell
tell application id \"sevs\" to tell process \"System Preferences\"
repeat until window \"Security & Privacy\" exists
delay 0.02
end repeat
tell scroll area 1 of group 1 of tab group 1 of window \"Security & Privacy\"
get value of static text 1 of UI element 1 of rows of table 1
end tell
end tell"
或者,如果所需專案(左側)的所需表視圖(右側)已經打開,您可以在 Catalina 上使用以下 osascript:
osascript -e "
tell application id \"sevs\" to tell process \"System Preferences\"
set frontmost to true
tell scroll area 1 of group 1 of tab group 1 of window \"Security & Privacy\" to get value of static text 1 of UI element 1 of rows of table 1
end tell"
uj5u.com熱心網友回復:
有必要排除與 GUI 的互動(在遠程系統上)。
與測驗遠程系統是MacOS的大蘇爾11.6和在檢查[√]允許遠程用戶的完整的磁盤訪問在系統偏好設定>共享>遠程登錄上遠程系統,那么例如 shell腳本 代碼在執行終端上的本地系統中一個ssh 會話到遠程系統會給你生什么下面列出的轉儲輔助功能在系統偏好設定>安全和隱私>無需使用AppleScript撰寫 UI 腳本即可保護隱私。
sqlite3 '/Library/Application Support/com.apple.TCC/TCC.db' 'SELECT client FROM access WHERE service="kTCCServiceAccessibility";'
在測驗系統上,它的輸出是:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Support/AEServer
com.apple.AccessibilityInspector
com.apple.Automator
com.apple.ScriptEditor2
com.apple.Terminal
com.latenightsw.ScriptDebugger8
但是,如果您確實需要使用AppleScript,您可以說您需要漂亮的輸出。換句話說,使用的AppleScript 腳本保存為一個外殼腳本使用#!/usr/bin/osascript 認領的輸出相同的上遠程系統將是例如:
AEServer, Accessibility Inspector, Automator, Script Editor, Terminal, Script Debugger
示例 AppleScript 代碼:
#!/usr/bin/osascript
set theAccessibilityList to paragraphs of (do shell script "sqlite3 '/Library/Application Support/com.apple.TCC/TCC.db' 'SELECT client FROM access WHERE service=\"kTCCServiceAccessibility\";'")
set theAccessibilityApplicationNamesList to {}
repeat with thisItem in theAccessibilityList
if thisItem starts with "/" then
set shellCommand to (do shell script "f=" & quoted form of thisItem & "; echo ${f##*/}")
set end of theAccessibilityApplicationNamesList to shellCommand
else
try
set end of theAccessibilityApplicationNamesList to the name of application id thisItem
end try
end if
end repeat
return theAccessibilityApplicationNamesList
筆記:
我創建,保存和由可執行的示例 的AppleScript 代碼,如上所示,在本地系統,然后將其復制的從本地系統到遠程系統使用scp。
Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/314058.html
