Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###########################################################
- # ABOUT
- ###########################################################
- (*
- Phil Stokes -- 2018
- applehelpwriter.com
- sqwarq.com
- Full article: http://applehelpwriter.com/2018/07/09/accessing-tcc-db-without-privileges/
- *)
- ###########################################################
- # DESCRIPTION
- ###########################################################
- (*
- get list of apps that are checked in Accessibility without requiring admin privileges
- works on 10.11 -> 10.14 beta
- *)
- ###########################################################
- # USAGE
- ###########################################################
- (*
- The script runner must itself be included in the list of Accessibility apps in order to work.
- Run the script and view the result in your Script Editor
- *)
- ###########################################################
- # IMPORT STATEMENTS
- ###########################################################
- use AppleScript version "2.4" -- Yosemite (10.10) or later
- use scripting additions
- ###########################################################
- # VARIABLES
- ###########################################################
- set os to do shell script "sw_vers -productVersion"
- ###########################################################
- # HANDLERS
- ###########################################################
- on getAccessibilityApps(vers) -- main workhorse to manipulate Sys Prefs app and extract info
- local appsList
- local canQuit
- set appsList to {}
- set canQuit to false
- (* more than one instance of Sys Prefs may target the wrong window *)
- try
- tell application "System Preferences" to quit
- end try
- (* launch a new instance of Sys Prefs as quietly as we can *)
- do shell script "open -Fg /Applications/System\\ Preferences.app"
- delay 1 -- wait for the ui to load
- tell application "System Preferences"
- reveal pane id "com.apple.preference.security"
- delay 1
- end tell
- try
- tell application "System Events"
- tell its application process "System Preferences"
- tell its window "Security & Privacy"
- tell its tab group 1
- if vers > 11 then -- Sierra and later use a different interface
- tell its UI element "Privacy" to click
- tell its UI element 5
- tell its table 1
- set uiNum to 7
- if vers > 13 then
- set uiNum to 8 -- Mojave moves Accessibility down a row
- end if
- tell its UI element uiNum
- tell its attribute "AXSelected"
- set its value to true -- click the Accessibility row
- end tell
- end tell
- end tell
- end tell
- end if
- tell its group 1
- tell its scroll area 1
- tell its table 1
- tell its attribute "AXRows"
- set theRows to value
- end tell
- set numRows to count of theRows
- repeat with i from 1 to numRows
- tell its row i
- tell its UI element
- (* is the item's checkbox checked or not? *)
- set val to value of its checkbox 1
- if val's first item is 1 then
- set end of appsList to name
- end if
- end tell
- end tell
- end repeat
- set canQuit to true
- end tell
- end tell
- end tell
- end tell
- end tell
- end tell
- end tell
- (* lets clean up after ourselves *)
- if canQuit is true then
- try
- tell application "System Preferences" to quit
- end try
- end if
- on error errMsg
- set end of appsList to (errMsg as text)
- end try
- return appsList
- end getAccessibilityApps
- on getVersFor(op) -- get the minor version number as a whole integer
- set o to offset of "." in op
- set postStr to text (o + 1) thru -1 of op
- try
- set o to offset of "." in postStr
- set numb to text 1 thru o in postStr as integer
- on error
- set numb to text 1 thru -1 in postStr as integer
- end try
- return numb
- end getVersFor
- on checkForError(aList) -- make sure the script runner has access or return error as result
- set returnList to aList
- if aList's item 1 contains "not allowed assistive access" then set returnList to aList's item 1 as text
- return returnList
- end checkForError
- on disembedList(aList) -- disembed nested lists one level deep
- set returnList to {}
- repeat with listItem in aList
- if class of listItem is list then
- repeat with i from 1 to count of listItem
- set sublist to item i of listItem
- set end of returnList to sublist
- end repeat
- else
- set end of returnList to listItem
- end if
- end repeat
- return returnList
- end disembedList
- ###########################################################
- # COMMANDS
- ########################################################
- set theList to getAccessibilityApps(getVersFor(os))
- set theList to disembedList(theList)
- checkForError(theList)
- ###########################################################
- #EOF
Add Comment
Please, Sign In to add comment