My script sets the Natural Scroll Direction of either a Mouse or Trackpad (MB trackpad or Magic Trackpad), but instead of allowing the user to choose which one is attached, I'd like to be able to programmatically execute one of the two functions based on what hardware is attached.
Is there a way to check (ie. AS or Shell Script) what hardware is attached?
For example, this is what I want to accomplish:
If: Trackpad is attached then run Trackpad function.
Else if: Mouse is attached, run Mouse function.
Else if: Mouse and Trackpad are attached, run both
Else: throw error, no input devices detected
I am after a robust function but have no idea where to start.
Mouse Function:
tell application "System Preferences"
reveal anchor "mouseTab" of pane id "com.apple.preference.mouse"
end tell
tell application "System Events" to tell process "System Preferences"
tell checkbox 1 of window 1 to if value is 1 then click
end tell
quit application "System Preferences"
Trackpad Function:
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.trackpad"
end tell
tell application "System Events"
tell application process "System Preferences" to tell tab group 1 of window "Trackpad"
click radio button 2
if value of checkbox 1 is 1 then
click checkbox 1
end if
end tell
end tell
quit application "System Preferences"
Thank you in advance, any help is greatly appreciated.
activatecommands. Note that as written, the code has no error handling and my require the use of adelaycommand between the events in the handlers. Nowadays I usually add much more code when dealing with UI Scripting, especially with System Preferences. As an example, see my answer https://apple.stackexchange.com/questions/419221/applescript-to-toggle-announce-the-time-in-sys-preferences/419239?r=SearchResults&s=4|0.0000#419239 to see the difference. – user3439894 May 01 '21 at 12:53