I could make it work by adding an Accessibility script to your existing script:
# Set the name of the item (app) you want to enable/disable
set theApp to "<the name of the app as it appears in the table>"
# Set this to true if you want to enable the item, or to false to disable it
set enableItem to true
tell application "System Preferences"
set securityPane to pane id "com.apple.preference.security"
tell securityPane to reveal anchor "Privacy_Microphone"
end tell
# Delay to give the system time to call the preferences pane
# Set it to the lowest value that reliably works with *your* setup
delay 0.8
tell application "System Events"
tell application process "System Preferences"
tell window 1
tell tab group 1
tell group 1
tell scroll area 1
tell table 1
repeat with r in rows
if name of UI element of r contains theApp then
tell checkbox 1 of UI element of r
set isEnabled to value as boolean
if enableItem ≠ isEnabled then click
set theResult to value as boolean
end tell
exit repeat
end if
end repeat
end tell
end tell
end tell
end tell
end tell
end tell
end tell
theResult
Note:
- The
theResult
variable only serves to report back the status of the checkbox after the Click action. - Settings are explained in the script.
Edit:
2019-08-25:
- Changed the action from toggling to a pre-settable action (enable or disable)
- Added some explanations in the script
2019-08-25T13:14+02
- Made the enable (click) condition a bit more compact