MacOS – Using applescript, how to move a window to the second display

applescriptdisplayfacetimemacos

I have experimented with absolutely every possible scripting option I can find on the web, and no matter what I do I cannot move a FaceTime window to my secondary display.

This works…

tell application "System Events" to tell process "FaceTime"
  tell application "FaceTime" to activate
  tell front window to set position to {3600, 500}
end tell

but with one fatal flaw that it always stops dead in its tracks, at the right edge of display #1 (the left display).

If I set the X coordinate to anything less than 2560 (my width on both screens) then it works perfectly, but any attempt to move it further to the right, and thus onto display #2, will not work.

I don't know if it's related, but my primary display is an external Dell, and my secondary display is the built-in display of the 27" iMac. Dell on the left, iMac on the right.

Interestingly however, if I manually drag the window onto display #2 and run the same script above, then it positions correctly onto display #2. It seems that the numbers are relative to whatever display the window is CURRENTLY on. How can I get it to absolutely position the window onto display #2?

Best Answer

It looks like Apple have set the window to be aware of what Display it should be on and not extend outside of thats Displays bounds when launching.

A side effect of this is the App will do the same thing with the calls from the applescript.

You can see this if you straddle the window across both Displays. Then quit and relaunch the app.

The window will open on only one of the displays and not be straddled.

If you did the same for say Safari. The window you had straddling would still be straddling.

I think you are out of luck doing it in any way useful.

The only way I got it to do it was to get the window and display details from the plist file '~/Library/Preferences/com.apple.FaceTime' while the window was on the second display.

 (* read plist file *)
    do shell script "/usr/bin/defaults read ~/Library/Preferences/com.apple.FaceTime NSWindow\\ Frame\\ FaceTimeWindowFrame"

Then when the app was on the first display.

Run a script which quit the app, rewrites the 'NSWindow Frame FaceTimeWindowFrame' entry in the plist with the info for the position and display I had from earlier.

Activate the app again, which would open on the second display. And then move it with the normal applescript code.

tell application "FaceTime" to quit
(do shell script "/usr/bin/defaults write ~/Library/Preferences/com.apple.FaceTime NSWindow\\ Frame\\ FaceTimeWindowFrame" & (" '2562 853 638 585 2560 240 1920 1200'") as string) --set to somewhere on my second screen

delay 1
tell application "System Events"

    tell application "FaceTime" to activate

    delay 4
    set position of window "FaceTime" of application process "FaceTime" to {3269, 315}

    end tell

But like I said not very useful. :-(