Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Move and resize app windows via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Move and resize app windows via AppleScript
Authored by: bgebhardt on Mar 17, '12 11:14:24AM

Very cool scripts. I added some code to automatically detect the screen size and pick a grid size. Kinda a quick hack without much testing, but thought I’d share it for the adventurous. Only works for one screen.

The first is for increasing screen size (Frontmost application window snap to grid reduce horizontally script). Paste at the top of the script and remove the duplicated set’s to the _gridSize and _screenWidth. The second bit is for decreasing screen size (Frontmost application window snap to grid increase horizontally script). It tries to pick a reasonable minimum window size.

These can be adapted for the other scripts, but that is left as an exercise for the reader.

FIRST BIT OF CODE

-- function returns width and height of the primary display
on displaySize()
	-- this only works with one display for now
	if my isOneDisplay() is true then
		tell application "Finder"
			set screen_resolution to bounds of window of desktop
			set screen_width to item 3 of screen_resolution
			set screen_height to item 4 of screen_resolution
		end tell
		return {screen_width, screen_height}
	else
		display dialog "Script doesn't work with multiple displays right now. [function: displayWidth()]"
		return 0
	end if
end displaySize

-- returns if one display or not.
on isOneDisplay()
	tell application "System Events"
		if (count every desktop) > 1 then
			return false
		else
			return true
		end if
	end tell
end isOneDisplay

-- picks a grid size automatically that gives 16 increments.  For width use item1 of displaySize().  For height use item 2 of displaySize()
set _gridSize to round ((item 1 of my displaySize()) / 16)
set _screenWidth to (item 1 of my displaySize()) -- change this to your screen width (or make it bigger than your screen width if you want bigger windows)

SECOND BIT OF CODE STARTS HERE:

on max(x, y)
	if x ≤ y then
		return y
	else
		return x
	end if
end max

-- function returns width and height of the primary display
on displaySize()
	-- this only works with one display for now
	if my isOneDisplay() is true then
		tell application "Finder"
			set screen_resolution to bounds of window of desktop
			set screen_width to item 3 of screen_resolution
			set screen_height to item 4 of screen_resolution
		end tell
		return {screen_width, screen_height}
	else
		display dialog "Script doesn't work with multiple displays right now. [function: displayWidth()]"
		return 0
	end if
end displaySize

-- returns if one display or not.
on isOneDisplay()
	tell application "System Events"
		if (count every desktop) > 1 then
			return false
		else
			return true
		end if
	end tell
end isOneDisplay

-- picks a grid size automatically that gives 16 increments.  For width use item1 of displaySize().  For height use item 2 of displaySize()
set _gridSize to round ((item 1 of my displaySize()) / 16)

-- set _gridSize to 64
set _safeSize to max(256, _gridSize * 2) -- attempts to automatically set to a reasonable size.  
-- change this if your new _gridSize is not a factor of 256 - not too small though! You can mess up the window!



[ Reply to This | # ]
Move and resize app windows via AppleScript
Authored by: philostein on Mar 02, '14 02:02:51AM

Looks good!

Are you still using these scripts? (I'm a little late replying…)



[ Reply to This | # ]