Advertisement
Guest User

Get list of Accessibility apps

a guest
Jul 5th, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###########################################################
  2. # ABOUT
  3. ###########################################################
  4. (*
  5.  
  6.  Phil Stokes -- 2018
  7.  applehelpwriter.com
  8.  sqwarq.com
  9.  
  10. *)
  11. ###########################################################
  12. # DESCRIPTION
  13. ###########################################################
  14. (*
  15.  
  16. get list of apps that are in checked in Accessibility without requiring admin privileges
  17. works on 10.11 -> 10.14 beta
  18.  
  19. *)
  20. ###########################################################
  21. # USAGE
  22. ###########################################################
  23. (*
  24.  
  25. The script runner must itself be included in the list of Accessibility apps in order to work.
  26. Run the script and view the result in your Script Editor
  27.  
  28. *)
  29. ###########################################################
  30. # IMPORT STATEMENTS
  31. ###########################################################
  32.  
  33. use AppleScript version "2.4" -- Yosemite (10.10) or later
  34. use scripting additions
  35.  
  36. ###########################################################
  37. # VARIABLES
  38. ###########################################################
  39.  
  40. set os to do shell script "sw_vers -productVersion"
  41.  
  42.  
  43. ###########################################################
  44. # HANDLERS
  45. ###########################################################
  46.  
  47. on getAccessibilityApps(vers) -- main workhorse to manipulate Sys Prefs app and extract info
  48.    
  49.     local appsList
  50.     local canQuit
  51.     set appsList to {}
  52.     set canQuit to false
  53.    
  54.     (* launch a new instance of Sys Prefs as quietly as we can *)
  55.     do shell script "open -Fg /Applications/System\\ Preferences.app"
  56.     delay 1 -- wait for the ui to load
  57.    
  58.     tell application "System Preferences"
  59.         reveal pane id "com.apple.preference.security"
  60.         delay 1
  61.     end tell
  62.     try
  63.         tell application "System Events"
  64.             tell its application process "System Preferences"
  65.                 tell its window "Security & Privacy"
  66.                     tell its tab group 1
  67.                         if vers > 11 then -- Sierra and later use a different interface
  68.                             tell its UI element "Privacy" to click
  69.                             tell its UI element 5
  70.                                 tell its table 1
  71.                                     set uiNum to 7
  72.                                     if vers > 13 then
  73.                                         set uiNum to 8 -- Mojave moves Accessibility down a row
  74.                                     end if
  75.                                     tell its UI element uiNum
  76.                                         tell its attribute "AXSelected"
  77.                                             set its value to true -- click the Accessibility row
  78.                                         end tell
  79.                                     end tell
  80.                                 end tell
  81.                             end tell
  82.                         end if
  83.                         tell its group 1
  84.                             tell its scroll area 1
  85.                                 tell its table 1
  86.                                     tell its attribute "AXRows"
  87.                                         set theRows to value
  88.                                     end tell
  89.                                     set numRows to count of theRows
  90.                                     repeat with i from 1 to numRows
  91.                                         tell its row i
  92.                                             tell its UI element
  93.                                                 (* is the item's checkbox checked or not? *)
  94.                                                 set val to value of its checkbox 1
  95.                                                 if val's first item is 1 then
  96.                                                     set end of appsList to name
  97.                                                 end if
  98.                                             end tell
  99.                                         end tell
  100.                                     end repeat
  101.                                     set canQuit to true
  102.                                 end tell
  103.                             end tell
  104.                         end tell
  105.                     end tell
  106.                 end tell
  107.             end tell
  108.         end tell
  109.         if canQuit is true then
  110.             tell application "System Preferences" to quit
  111.         end if
  112.     on error errMsg
  113.         set end of appsList to (errMsg as text)
  114.     end try
  115.     return appsList
  116. end getAccessibilityApps
  117.  
  118.  
  119. on getVersFor(op) -- get the minor version number as a whole integer
  120.     set o to offset of "." in op
  121.     set postStr to text (o + 1) thru -1 of op
  122.     try
  123.         set o to offset of "." in postStr
  124.         set numb to text 1 thru o in postStr as integer
  125.     on error
  126.         set numb to text 1 thru -1 in postStr as integer
  127.     end try
  128.     return numb
  129. end getVersFor
  130.  
  131. on checkForError(aList) -- make sure the script runner has access or return error as result
  132.     set returnList to aList
  133.     if aList's item 1 contains "not allowed assistive access" then set returnList to aList's item 1 as text
  134.     return returnList
  135. end checkForError
  136.  
  137.  
  138. on disembedList(aList) -- disembed nested lists one level deep
  139.     set returnList to {}
  140.     repeat with listItem in aList
  141.         if class of listItem is list then
  142.             repeat with i from 1 to count of listItem
  143.                 set sublist to item i of listItem
  144.                 set end of returnList to sublist
  145.             end repeat
  146.         else
  147.             set end of returnList to listItem
  148.         end if
  149.     end repeat
  150.     return returnList
  151. end disembedList
  152.  
  153.  
  154. ###########################################################
  155. # COMMANDS
  156. ########################################################
  157.  
  158. set theList to getAccessibilityApps(getVersFor(os))
  159. set theList to disembedList(theList)
  160. checkForError(theList)
  161.  
  162.  
  163. ###########################################################
  164. #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement