Adding a script to MacOS 101
June 12, 2022 10:37 PM   Subscribe

Both my personal and work laptops have the M1 chip and I use the HyperDrive 10-in-1 hub to connect two external displays to them. This means a couple times a day I unplug a laptop from its power supply and the hub and plug the other laptop into its power supply and the hub. Plugging in the laptop comes with some lag in the connections to the monitors and my open applications end up on the wrong display. Can I create a shortcut or a script that will let me move an app and its windows to a specific display and maximize it in the window?

I've looked at Automator, AppleScript, XCode and Shortcuts but I don't know where to start.

I see some applications now that have choices in their Window menu:
Move to Dell U2415
Move to Dell P2415Q
Move to Retina Display

There are also options in the dock that let you do this but I want to do it on the fly.

I want a script that will let me focus an app and press ⌘-1 to move it to the screen on the left and press ⌘-2 to move it to the screen on the right.

I'm happy to write some code - this project will be a good intro for me to learn the capabilities of scripting on MacOS.
posted by bendy to Technology (7 answers total) 2 users marked this as a favorite
 
Maybe Moom can help here?
posted by conradjones at 10:48 PM on June 12, 2022


Use the Shortcuts app! Someone has solved this problem for you. :)

https://www.youtube.com/watch?v=fikngk2Ojt0
posted by GiveUpNed at 11:20 PM on June 12, 2022


If you want to automate that process, that would require some scripting. But if all you'd like to do is have a keyboard shortcut that moves windows to different monitors, you can set that up in System Preferences > Keyboard > Shortcuts (one of the sections at the top) > App Shortcuts (in the list on the left).

Make sure the keyboard shortcut has the exact same name as the command you're trying to do. That is, from your question:

Move to Dell U2415
Move to Dell P2415Q
Move to Retina Display
posted by emelenjr at 7:08 AM on June 13, 2022


Best answer: Take a look at Better Touch Tool. It started out as a way to customize touchpad interactions (thus the name), but it's developed quite a lot of scripting ability, and it makes it easy to move windows between screens and resize them using keyboard commands.
posted by adamrice at 8:53 AM on June 13, 2022


I don't know about the scripting but Rectangle (or its predecessor Spectacle) is nice for maximizing windows and moving them between displays. It's about equivalent to the Win+Arrow shortcuts in Windows.

also I think your problem might not happen if you make your laptop display the main display, or put the laptop in clamshell mode.
posted by neckro23 at 11:09 AM on June 13, 2022


Response by poster: emelenjr - what if I want to do some scripting? Where would I start?
posted by bendy at 4:13 PM on June 13, 2022


Response by poster: I used a combination of Better Touch Tool and AppleScript to make a keyboard shortcut that does exactly what I wanted. Thanks all!
posted by bendy at 8:27 PM on June 13, 2022


« Older Passion Fruit Honey Puree- give me ideas!   |   Teaching kid about bodies and consent Newer »
This thread is closed to new comments.