Playing with AppleScript I want to manipulate the location of a few windows with position
but I'm having an issue defining the monitor. Currently I have several different size and brand monitors I connect to with my MacBook during my travels. The only repeating occurrence with all four monitors I connect to is that the monitor I want to manipulate includes the menu bar.
When testing with do shell script "system_profiler SPDisplaysDataType
I'm not sure if the returned text of Main Display: Yes
considers the main to be where the menu bar resides from the extraction:
Graphics/Displays:
Intel Iris Pro:
Chipset Model: Intel Iris Pro
Type: GPU
Bus: Built-In
VRAM (Dynamic, Max): 1536 MB
Metal: Supported
Displays:
Color LCD:
Display Type: Built-In Retina LCD
Resolution: 2880 x 1800 Retina
Mirror: Off
Online: Yes
Rotation: Supported
Automatically Adjust Brightness: Yes
Connection Type: DisplayPort
Thunderbolt Display:
Display Type: LCD
Resolution: 2560 x 1440
Main Display: Yes
Mirror: Off
Online: Yes
Rotation: Supported
Automatically Adjust Brightness: No
Connection Type: DisplayPort
If my assumption of the Main Display
is correct how should I properly grep the resolution of the identified main display so I can manipulate the windows?
When I research it would appear some commonly just step into each display:
- Positioning a window with AppleScript using dual monitors
- Run AppleScript for Specific Monitor
- Cannot get or set the window size of some apps using AppleScript?
- Set position of window with AppleScript
So I don't know if this would be two questions in one. I'm somewhat confused on how the sequence is determined when connecting to multiple monitors (such as today I might be connected to a thunderbolt display but tomorrow I might be connected to two Dells monitors through my two DisplayPorts) and if there is a way to target a monitor in particular based on the menu bar.
I can already detect the app and it's size with:
tell application "System Events" to tell application process "Notes" to set theSize to get size of window 1
set theWidth to item 1 of theSize
set theHeight to item 2 of theSize
but my issue falls in determining the resolution so I can calculate the position
and bounds
to move the app window.
Best Answer
UPDATE
Removed my original answer. Here is a completely different approach which I prefer over my original solution. This version actually uses “Image Events” scripting addition.
This script will get the names of the displays connected to your computer. The returned values of “display "Display 1" will always be “which monitor has the menu bar in AppleScript?”