Move Window by a Pixel

I have been using optimal layout for years but it's not in development anymore and I am sure KM can replace it but I am not sure how to do it.

The main thing that optimal layout does that no other app can do (except KM) is to move a window by pixel.

So, I am holding down opt+cmd+right arrow and the window is moving a few pixels for every second that I hold it down. This way I can move a window from one monitor to another by using the keyboard.

Can you please give me a macro library that will move a window by pixel? Also, the other macro library that moves windows (see here Here's a macro library to move windows with numeric keypad) actually moves it to my small monitor and keeps it there. Could you provide a macro library that can manipulate a window to full screen (for example) and keep it on same monitor and adjust according to monitor size?

Thank you

I haven't tried Optimal Layout. Looks interesting, but I'm scared of the "not under active development" notice on the website. I will try it.

Today I carry my work-supplied MacBook Pro laptop back and forth from home to work every day. I use a single monitor at work and a single monitor at home. They are different sizes. I've experimented several times with using my MacBook's native screen as an extra monitor, for a dual-monitor experience. Every time, I've given up because I didn't like the problems caused by the monitors having different sizes, where the menu bar goes, what happens when I disconnect my MacBook to go to a meeting, etc.

I will soon (the end of this month) get a new MacBook laptop, and dual monitors at work. They will be identical 24-inch monitors. At that time, I'll also switch to the Mojave operating system. KM depends on the operating system's hooks to control windows. Currently, macOS High Sierra just doesn't expose enough information about monitor layouts to KM. Maybe that will improve with Mojave. Anyway, when I have dual monitors, I'll have an incentive to see if I can fix my KM library to better coexist with dual monitors. I'll probably experiment again with adding the laptop's native screen. A colleague uses his MacBook Pro in that configuration, for a total of 3 monitors, and it seems to be great.

I'm sure KM can move a window by pixel, though I'm not sure I need to do that. I'd rather come up with a "standard" layout for the applications that I use every day at home and work. I already have KM macros called "arrive at work", "leave work", "arrive home", etc. So when I arrive at work, I plug in and invoke the macro, and it starts several apps, mounts network drives, etc. I plan to extend the macro to move windows to various "standard" places on the different monitors. Then as I work, I use the window-placement macros to manage transient windows.

Thanks for the reply! Yes that's why I want to find alternative. I've been using it for years and didn't realize how much I use it every day until now. It still works though but since mojave is out I want to make sure all my apps are ready for it etc... so I'm doing a bit of cleaning/deleting of unused out-dated apps.

Hey Pete,

I wouldn't bother. It's pretty broken and will get worse.

Keyboard Maestro can easily manage window layouts, although you have to brave through the screen-token syntax and the math. (There are decent number of templates to get you started though.)

If you want a more user-friendly UI then take a look at Moom and Witch from ManyTricks, which are still under active development.

I own several of their utilities.

-Chris

Hey @devananda,

Moom does that easily**, but Keyboard Maestro is no slouch.

Open the Keyboard Maestro Editor and open the “Window” menu.

Open the “Macro Library” window.

Go to the “Window” category.

Double-Click on the “Move and Resize Windows” item to install.

Scope-out how the individual macros work.

NOTE – that you have to open the palette first for the macros to work.

** Moom is likely to see more window types than Keyboard Maestro, but I haven't extensively tested and cannot say for certain.

-Chris

Thanks, Chris! I'll check out Moom.

1 Like

oh I didn't realize Moom does this as well. Thanks for the input @siemsen I've already got keymou and witch so I like their products (use them everyday).

I can see the different solutions offered here than mean an AppleScript solution isn’t required. But I’ll leave it here to perhaps be of use to someone else, or for when a third-party solution breaks in the future.

use application "System Events"
property process : a reference to (the first process where it is frontmost)
--------------------------------------------------------------------------------
property |𝚫| : 1 -- The number of pixels by which to move the window
--------------------------------------------------------------------------------
--IMPLEMENTATION:
tell the frontWindow to move right_
--OR:
--tell the frontWindow to move left_
--tell the frontWindow to move up_
--tell the frontWindow to move down_
--------------------------------------------------------------------------------
--SCRIPT OBJECTS & HANDLERS:
script frontWindow
	property window : a reference to window 1 of my process
	#property position : a reference to position of my window
	
	to move direction
		local direction
		
		script
			property fn_ : direction
		end script
		
		result's fn:(a reference to the position ¬
			of (a reference to my window))
	end move
end script

on up:position
	local position
	global |𝚫|
	
	set {x, y} to position's contents
	set contents of position to {x, y - |𝚫|}
	{x, y}
end up:
on down:position
	local position
	global |𝚫|
	
	set {x, y} to position's contents
	set contents of position to {x, y + |𝚫|}
	{x, y}
end down:
on |left|:position
	local position
	global |𝚫|
	
	set {x, y} to position's contents
	set contents of position to {x - |𝚫|, y}
	{x, y}
end |left|:
on |right|:position
	local position
	global |𝚫|
	
	set {x, y} to position's contents
	set contents of position to {x + |𝚫|, y}
	{x, y}
end |right|:
---------------------------------------------------------------------------❮END❯

I installed the Move Windows set from the Macro Library using the above instructions. I had not yet discovered those macro sets. They are not the same set as the Macro Library macros in the forum here, even though they have the same name.

I made some customizations to the set. I didn't like ⌃W to trigger the menu because I have too many apps that use ⌃W as a hotkey, so I made a little more complicated and less likely to trip on something unexpectedly. I also thought that the menu should show the keys for the movements, so I added the key symbols to each macro name.

Here's the results in the editor:

And here's the resulting menu:
image

Because the menu and the editor use different fonts, there's three cases where I had to add an extra Tab to the name to get the menu to align properly. It would take some fiddling to get the hotkeys right-aligned, so I haven't bothered with that yet.

If people want these mods, I'll upload the set.

1 Like