📄

Switching Between Trackpad and Mouse Setups with AppleScript

This article was automatically translated from theJapanese original by AI. It may contain translation errors.

This post was published over 4 years ago. Its content may be outdated.

When I use a mouse at home and the trackpad while out with my MacBook, the scroll direction differs :japanese_goblin: (Logicool and others handle this in software.) So to switch the scroll direction I had been going to [System Preferences] -> [Trackpad] -> [Scroll direction: Natural], but it turns out I can automate this with AppleScript.

Environment

macOS Monterey 12.2

Steps

  1. Write a script in AppleScript that switches the scroll direction
  2. Export the code as an application
  3. Set up a program in the “Shortcuts.app” that launches the exported application so it can run with one click

Script to Switch Scroll Direction

The site I referenced

set didRunSystemPreferences to get running of application "System Preferences"

tell application "System Preferences"
	set current pane to pane "com.apple.preference.trackpad"
	tell application "System Events" to tell tab group 1 of window "トラックパッド" of application process "System Preferences"
		click checkbox 1
	end tell
end tell

if not didRunSystemPreferences then
	quit application "System Preferences"
end if

Screenshot 2022-01-29 14.07.46.png Open Spotlight, type “Script Editor”, and press Enter. Create a new document and paste the code above. Screenshot 2022-01-29 14.06.32.png

Exporting

Click [File] -> [Export] in the menu bar. Screenshot 2022-01-29 14.06.39.png In the dialog that appears, set the save location to [Applications], set the [File Format] to Application, and click [Save]. Screenshot 2022-01-29 14.06.55.png

Permission Setup

Go to [System Preferences] -> [Security & Privacy] -> [Accessibility], press the + button, and add the application you just exported. Screenshot 2022-01-29 14.07.33.png

One-Click Launch

Open Shortcuts.app and press + in the [menu bar]. Screenshot 2022-01-29 14.08.44.png Click [Scripting] on the right and drop in [Run AppleScript]. Screenshot 2022-01-29 14.08.55.png Paste the following code ("toggleTrackpad" is the name of the application you exported).

tell application "toggleTrackpad"
	activate
end tell

Screenshot 2022-01-29 14.09.28.png

Check

If it has been added to the menu bar, you’re all set. Screenshot 2022-01-29 14.09.43.png

Wrapping Up

Enjoy your comfortable MacBook life.

Sites I Referenced

https://qiita.com/satosystems/items/8fff5b2313ecd6f81af3 https://zenn.dev/rot1024/articles/mac_keyboard_layout_monterey

Recent Articles

Network(beta)

Drag to move / Ctrl+wheel to zoom