Full Screen Your Applications (Zoom Button Replacement)

Since I was a little bit bored and I was already annoyed for a long time about the OSX zoom button, I thought of making an AppleScript to zoom the first window of an open application so it fills up the whole (visible) screen. To do this I of course needed to get the frame of the full screen and the frame of the visible screen. This could easily be done with a command line utility. After using the command line utility, I just had to calculate the left upper corner and the right upper corner and it was done.

CLU Source:

AppleScript:

property CLUPosix : missing value

on run
	-- GET CLU
	checkForCLU()
	
	-- CHOOSE PROCESS
	tell application "System Events" to set allProcesses to name of every application process whose visible is true and name is not "Full Screener"
	tell me to activate
	set chosenProcess to choose from list allProcesses with prompt "Choose your process:"
	if chosenProcess is false then return
	set chosenProcess to chosenProcess as string
	
	-- check if process is scriptable
	tell application "System Events" to set scriptFlag to has scripting terminology of process chosenProcess
	if scriptFlag is false then
		display dialog (chosenProcess & " is not scriptable.") buttons "OK" default button 1
		return
	end if
	
	-- MAGNIFY FIRST WINDOW
	tell application chosenProcess to set allWindows to every window
	
	-- check if app has windows
	if (count allWindows) is 0 then
		display dialog (chosenProcess & " has no open window.") buttons "OK" default button 1
		return
	end if
	
	-- get visible screen frame
	set fullScreen to screenFrame(false)
	set visibleScreen to screenFrame(true)
	set x to (visibleScreen's x)
	set y to (fullScreen's height) - (visibleScreen's y) - (visibleScreen's height)
	set myWidth to (visibleScreen's x) + (visibleScreen's width)
	set myHeight to y + (visibleScreen's height)
	
	-- if "Finder"
	if chosenProcess is "Finder" then set y to 44
	
	-- set bounds
	try
		tell application chosenProcess to set bounds of window 1 to {x, y, myWidth, myHeight}
	on error theMsg
		display dialog "An error occured while resizing the window." buttons {"Show Error", "OK"} default button 2 cancel button 2
		display dialog "Error Message:" & return & return & theMsg buttons "OK" default button 1
	end try
end run

on screenFrame(visibleFrame)
	-- ARGUMENTS
	if visibleFrame is true then
		set args to "-v YES -s 1"
	else
		set args to "-v NO -s 1"
	end if
	
	set screenFr to do shell script (quoted form of CLUPosix & " " & args)
	
	-- MAKE LIST
	-- X
	setTID("x:")
	set x to text item 2 of screenFr
	setTID(" ")
	set x to text item 1 of x
	
	-- Y
	setTID("y:")
	set y to text item 2 of screenFr
	setTID(" ")
	set y to text item 1 of y
	
	-- width
	setTID("width:")
	set myWidth to text item 2 of screenFr
	setTID(" ")
	set myWidth to text item 1 of myWidth
	
	-- height
	setTID("height:")
	set myHeight to text item 2 of screenFr
	setTID("")
	
	-- RESULT
	return {x:x, y:y, width:myWidth, height:myHeight}
end screenFrame

on setTID(delim)
	set AppleScript's text item delimiters to delim
end setTID

on checkForCLU()
	-- if missing value
	if CLUPosix is missing value then
		-- contents
		try
			set CLU to ((path to me as text) & "Contents:Resources:ScreenFrame") as alias
			set CLUPosix to (POSIX path of CLU)
		on error
			set CLU to (choose file with prompt "The Command Line Uitlity was not found. Please locate it manually.")
			set CLUPosix to (POSIX path of CLU)
		end try
		
		return
	end if
	
	-- if not exists
	set CLU to (POSIX file CLUPosix) as string
	try
		set CLU to CLU as alias
	on error
		try
			set CLU to ((path to me as text) & "Contents:Resources:ScreenFrame") as alias
			set CLUPosix to (POSIX path of CLU)
		on error
			set CLU to (choose file with prompt "The Command Line Uitlity was not found. Please locate it manually.")
			set CLUPosix to (POSIX path of CLU)
		end try
	end try
	
	return
end checkForCLU

After choosing an application the script first checks if the application is scriptable and if the application has any open window. If not, the script displays a dialog and stops running.

I hope this will be helpful for some people,
ief2

PS: A ready to use download is available at http://developerief2.site11.com/Public-Files/Full_Screener.zip

I found this a bit simpler:

tell application "Finder"
	set dtBounds to bounds of window of desktop
end tell
tell application (path to frontmost application as text)
	set the bounds of the first window to dtBounds
end tell

This is indeed a little bit simpler. I used this until I had the idea of placing my dock to the left side of my display. And boom! The script placed the window underneath the dock. So I came up with the other script. Wat it really does is calculating the location of the dock.

How about this? I am not sure whether the “tilesize” and “dock orientation” defaults exist on a new machine. So I handled the orientation via a try block. You can modify the 14 for a looser or tighter fit. But I like a pixel or so between.


tell application "Finder" to set DT_bounds to bounds of window of desktop

set dock_tiles to do shell script "defaults read com.apple.dock tilesize"
-- "48"
try
	set dock_orientation to do shell script "defaults read com.apple.dock orientation"
	-- "right", "bottom", or "left"
on error
	set dock_orientation to "bottom"
	-- maybe error if none ever set? If so, "bottom"
end try

if dock_orientation = "bottom" then
	set a_bound to ((item 4 of DT_bounds) - dock_tiles - 14)
	set item 4 of DT_bounds to a_bound
end if

if dock_orientation = "right" then
	set a_bound to ((item 3 of DT_bounds) - dock_tiles - 14)
	set item 3 of DT_bounds to a_bound
end if

if dock_orientation = "left" then
	set a_bound to ((item 1 of DT_bounds) + dock_tiles + 13)
	set item 1 of DT_bounds to a_bound
end if
--DT_bounds

tell application (path to frontmost application as text)
	set the bounds of the first window to DT_bounds
end tell

wrongzoom on github