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