Jump to content

MonitorJumper - move the top-most window between your monitor(s)


Recommended Posts

Hey,

I saw a workflow request on /r/Alfred that interested me as well, and saw that no one made it yet, so I quickly wrapped up one with a little bit of Google-ing.

 

Basically, it's a really basic workflow that moves your current window between monitor(s) with the tap of a hotkey or by entering "jump" into Alfred (both are configurable of course).

 

I don't think I'll be maintaining this workflow, as there really is not much to maintain, it's a very simple AppleScript behind, but feel free to comment here and I'll check it every once in a while to see if anything is needed.

 

Download

Edited by The_Ben
Link to comment

Hey,

I saw a workflow request on /r/Alfred that interested me as well, and saw that no one made it yet, so I quickly wrapped up one with a little bit of Google-ing.

 

Basically, it's a really basic workflow that moves your current window between monitor(s) with the tap of a hotkey or by entering "jump" into Alfred (both are configurable of course).

 

I don't think I'll be maintaining this workflow, as there really is not much to maintain, it's a very simple AppleScript behind, but feel free to comment here and I'll check it every once in a while to see if anything is needed.

 

Download

 

Wish I could use it... Too bad Apple screwed my monitor up in 10.8.3. 

Link to comment
  • 4 months later...
  • 1 year later...
  • 5 years later...

Hi you might be interested in this. I build it for LaunchBar. But since it is just an applescript you should be able to make it work just fine in Alfred with just a few changes. It's a few lines of code. But it should cover pretty much all the bases.

 

# http://superuser.com/questions/331313/how-to-automagically-move-windows-between-monitors-with-one-keystroke
# https://stackoverflow.com/questions/6565703/math-algorithm-fit-image-to-screen-retain-aspect-ratio
# https://forum.latenightsw.com/t/get-sizes-of-monitor-s-via-applescript/1351/10

---
use framework "Foundation"
use framework "AppKit"
use scripting additions

set allFrames to (current application's NSScreen's screens()'s valueForKey:"frame") as list
try
	set _mon1 to item 2 of item 1 of allFrames
	set _mon2 to item 2 of item 2 of allFrames
	
	set _mon1Width to item 1 of _mon1
	set _mon1Hight to item 2 of _mon1
	set _mon1Size to _mon1Width + _mon1Hight
	
	
	set _mon2Width to item 1 of _mon2
	set _mon2Hight to item 2 of _mon2
	set _mon2Size to _mon2Width + _mon2Hight
	
	set _screenWar to (_mon2Width / _mon1Width) # width adaption ratio of screen 1 & 2
	set _screenHar to (_mon2Hight / _mon1Hight) #  hight adaption ratio of screen 1 & 2 
	
	tell current application to set _hightoffset to do shell script "/usr/libexec/PlistBuddy -c 'Print :DisplayAnyUserSets:Configs:0:0:CurrentInfo:OriginY ' /Library/Preferences/com.apple.windowserver.displays.plist"
	set _hightoffset to _hightoffset as feet as number
	
	tell current application to set _widthoffset to do shell script "/usr/libexec/PlistBuddy -c 'Print :DisplayAnyUserSets:Configs:0:0:CurrentInfo:OriginX ' /Library/Preferences/com.apple.windowserver.displays.plist"
	set _widthoffset to _widthoffset as feet as number
	
	# detect position of the second screen in relation to the main screen
	if _mon1Width = _widthoffset then
		# say "Rechts"
		set _right to true
	else if _mon1Hight = _hightoffset then
		set _right to false
		set _bottom to true
	else if _mon2Width = -_widthoffset then
		set _right to false
		set _bottom to false
		set _left to true
	else if _mon2Hight = -_hightoffset then
		set _right to false
		set _bottom to false
		set _left to false
		set _top to true
	end if
end try

try
	tell application "System Events"
		tell (first process whose frontmost is true)
			set _windowPos to position of window 1
			set x to item 1 of _windowPos # x = position width 
			set y to item 2 of _windowPos # y = position hight 
			
			set _windowSize to size of window 1
			set _windowWidth to (item 1 of _windowSize)
			set _windowHight to (item 2 of _windowSize)
			
			
			# set current location (which monitor) of the frontmost window and new window size and postion 
			if _right is true then
				if x < _mon1Width then
					set _newSize to {_windowWidth * _screenWar, _windowHight * _screenHar}
					set _newPosition to {(x * _screenWar) + _widthoffset, ((y - 25) * _screenHar) + (_hightoffset + 25)} # menubar = 25 pixel
					set _winLocation to "mon1"
				else
					set _newPosition to {(x - _widthoffset) / _screenWar, ((y - (_hightoffset + 25)) / _screenHar) + 25}
					set _newSize to {_windowWidth / _screenWar, _windowHight / _screenHar}
					set _winLocation to "mon2"
				end if
				
			else if _bottom is true then
				if y < _mon1Hight then
					set _newPosition to {(x * _screenWar) + _widthoffset, ((y - 25) * _screenHar) + (_hightoffset + 25)}
					set _newSize to {_windowWidth * _screenWar, _windowHight * _screenHar}
					set _winLocation to "mon1"
				else
					set _newPosition to {(x - _widthoffset) / _screenWar, ((y - (_hightoffset + 25)) / _screenHar) + 25}
					set _newSize to {_windowWidth / _screenWar, _windowHight / _screenHar}
					set _winLocation to "mon2"
				end if
			else if _left is true then
				if x > -1 then
					set _newSize to {_windowWidth * _screenWar, _windowHight * _screenHar}
					set _newPosition to {(x * _screenWar) + _widthoffset, ((y - 25) * _screenHar) + (_hightoffset + 25)}
					set _winLocation to "mon1"
				else
					set _newPosition to {(x - _widthoffset) / _screenWar, ((y - (_hightoffset + 25)) / _screenHar) + 25}
					set _newSize to {_windowWidth / _screenWar, _windowHight / _screenHar}
					set _winLocation to "mon2"
				end if
			else if _top is true then
				if y < 25 then
					set _newPosition to {(x - _widthoffset) / _screenWar, (y + (-_hightoffset - 25)) / _screenHar + 25}
					set _newSize to {_windowWidth / _screenWar, (_windowHight + 25) / _screenHar - 25}
					set _winLocation to "mon2"
				else
					set _newSize to {_windowWidth * _screenWar, (_windowHight + 25) * _screenHar - 25}
					set _newPosition to {(x * _screenWar) + _widthoffset, ((y - 25) * _screenHar) + _hightoffset + 25}
					set _winLocation to "mon1"
				end if
			end if
			
			# checking for window loaction and whether the monitor it is located on is bigger or smaller than the other one 
			if _winLocation is "mon1" then
				if _mon1Size > _mon2Size then
					set size of window 1 to _newSize
					set position of window 1 to _newPosition
				else
					set position of window 1 to _newPosition
					set size of window 1 to _newSize
				end if
				
			else
				if _mon2Size > _mon1Size then
					set size of window 1 to _newSize
					set position of window 1 to _newPosition
				else
					set position of window 1 to _newPosition
					set size of window 1 to _newSize
				end if
			end if
			
		end tell
	end tell
end try

There are more window actions on my github. Under the hood they are all applescripts https://github.com/Ptujec/LaunchBar/tree/master/Window%20Actions 

Edited by Ptujec
Link to comment
On 9/10/2013 at 12:51 AM, stonefury said:

I position my laptop below my larger monitor, so it won't work for this case. Will be easy to fix, just mentioning in case there was a way to better identify the monitor to move the window to.

Check my script below. This should work no matter how you position monitors or whether one is bigger or smaller … as long as it's just two. Didn't try it for more. If you are still interested 7 years + later ;)

Link to comment
  • 1 year later...

Thanks for the script! I tried running it in macOS Monterey and got the following error:

ERROR: Print: Entry, ":DisplayAnyUserSets:Configs:0:0:CurrentInfo:OriginY", Does Not Exist

I tried google-ing and couldn't find anything related to this error, did the name of DisplayAnyUserSets Configs change in the latest update?

Edited by krishnan
Link to comment
  • 9 months later...
On 10/3/2022 at 6:12 AM, TomBenz said:

Yes, I shifted to using automation tasks. I also have one for removing windows from full screen, shift to other monitor and then again to full screen. Automation task is great in Alfred 5

 

@vitor How do I use automation task to get and move all windows from one monitor to other? When I am sharing screen on teams, I would like only teams app windows to remain on primary montior (retina display) and move everything else on other monitor. Suggest how this can be done. Thanks in advance

Link to comment
10 hours ago, sosaveme said:

Is it possible to move fullscreen app or fullscreen video?

You can use Automation tasks to create a workflow for this. Steps are keyword or shortcut to trigger --> key combo (ctrl + command + F) to move the window out of full screen mode, move to next monitor and again make the app full screen. 

Link to comment
6 hours ago, TomBenz said:

You can use Automation tasks to create a workflow for this. Steps are keyword or shortcut to trigger --> key combo (ctrl + command + F) to move the window out of full screen mode, move to next monitor and again make the app full screen. 

 

Thanks! Sadly but this method doesn't work properly for safari full screen video, because it's move whole safari :(

Link to comment

@TomBenz That is quite complex and specific, especially because you’re wanting to move every window not belonging to an app. That needs a bespoke solution.

 

@sosaveme It’s not possible to do that, even manually. The video is part of the tab/window it comes from. And indeed, Apple does not provide an API to programatically move between spaces.

Link to comment
4 hours ago, vitor said:

@TomBenz That is quite complex and specific, especially because you’re wanting to move every window not belonging to an app. That needs a bespoke solution.

 

@sosaveme It’s not possible to do that, even manually. The video is part of the tab/window it comes from. And indeed, Apple does not provide an API to programatically move between spaces.

 

Thanks @vitor for your response. Is it possible to move all windows without exception then? I can then manually move teams windows back to main window? 

 

https://stackoverflow.com/questions/20554602/applescript-get-list-of-windows-on-all-desktops/67338053#67338053  I see this AppleScript to get list of windows -- How can this combined with move automation task or modified to achieve this/

Link to comment
Just now, TomBenz said:

 

Thanks @vitor for your response. Is it possible to move all windows without exception then? I can then manually move teams windows back to main window? 

 

https://stackoverflow.com/questions/20554602/applescript-get-list-of-windows-on-all-desktops/67338053#67338053  I see this AppleScript to get list of windows -- How can this combined with move automation task or modified to achieve this/

 

would be great if somebody can guide / help or write a workflow for it.

Link to comment
2 minutes ago, TomBenz said:

would be great if somebody can guide / help or write a workflow for it.

I really would simply use something like Moom. Sometimes it's better to use something specifically designed for a task rather than trying to reinvent the wheel.

 

Stephen

Link to comment
20 minutes ago, Stephen_C said:

I really would simply use something like Moom. Sometimes it's better to use something specifically designed for a task rather than trying to reinvent the wheel.

 

Stephen

thank you @Stephen_C. I had used this app once before and will try again. Will this be able to move all windows in one go? 

 

I also use Rectangle (moved to this from Spectacle) but find windows management workflow via Alfred itself easy to use and update. 

Link to comment
13 minutes ago, TomBenz said:

I had used this app once before and will try again. Will this be able to move all windows in one go?

I'm not sure this is a subject for this forum: we risk derailing the thread. However, on the page to which I previously linked read the section headed "Save and restore window layouts”, which includes the following:

 

Quote

This feature is particularly useful if you use a laptop with an external display—Moom can trigger saved layouts on addition or removal of displays.

I use that feature and it works well.

 

Stephen

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...