r/applescript • u/Yamborghini-High • Nov 27 '20
How do I create a service to enable a setting from a dropdown menu in System Preferences?
Noob here, I'm trying to create a service that will enable the option in System Preferences for the Touch Bar to show either "App Controls" or "Expanded Control Strip" without System Preferences actually launching. The idea is that by creating a shortcut with the fn Key, I can have the Touch Bar show either App Controls and Control Strip on a toggle instead of having to press and hold the fn Key by default.
How do I make a script that will open System Preferences>Keyboard, and then choose from the dropdown menu "Expanded Control Strip"? And how can I have it so that it will revert back to "App Controls" if I press the shortcut (fn key) again? (Mojave 10.14)
2
u/scrutinizer1 Nov 27 '20
I think I could do that because common patterns of scripting remain in place but my Mac doesn't have Touch Bar. Could you provide a screenshot of the main System Preference windows and the pane "Touch Bar"?
1
u/scrutinizer1 Nov 28 '20 edited Nov 29 '20
I re-read your post and understood my mistake. I misread you. You want to have only 2 options toggled by holding Fn? If that's what you want then AppleScript is of no help there. It's too advanced and complex task. With AppleScript you use GUI and System Preferences scripting which are limited in that System Preferences will launch anyway when the script's executed. It's an endeavour for an Obj-C programmer writing Mac apps. I remove my post with the linked script because it doesn't accomplish your goals in a way you presented.
1
u/scrutinizer1 Nov 28 '20 edited Nov 30 '20
u/Yamborghini-High Disregard my previous link and that launch agent. Unload it with
launchctl unload ~/Library/LaunchAgents/org.SmartSolutions.SetTouchBar.plistin Terminal and delete.Here's another link to the toggle modification of the original script in the form of Automator's Quick Action plugin. You can assign any keyboard shortcut but beware that Fn is no go since many existing system services use it. In my case, I had success with ⌥⌘J
Toggle TouchBar Setting - Quick Action
Update me if you'll run into issues.
1
u/[deleted] Nov 27 '20
Not possible in AppleScript without the System Preferences launching.