Applescript Final Project Done!!

Well many thanks to Mod Nigel Garvey for his help as well as countless other folks doing Applescipt who are willing to share their knowledge.

Just finished a pet project for my vintage PowerMac G4 (Dual 1.42 MDD - OSX 10.4.11/OS 9.2.2). As most PPC users know Flash is pretty bad on these older systems, but it has come to the attention of many that if one lowers the resolution of the monitor that is playing the video (especially in fullscreen) it runs quite a bit better. Well, here is my little contribution to the cause. It requires:

Unsanity’s Shadowkiller http://unsanity.com/haxies/shadowkiller (reduces the load on video RAM),

RightZoom http://www.macupdate.com/app/mac/30591/right-zoom (resizes windows after switches - great app to have anyway),

and CScreen http://hintsforums.macworld.com/attachment.php?s=7bf9837ac3a9274242d97c227d0b7c9c&attachmentid=1416&d=1156306718

Basically, the user jots down the full-size monitor resolution/s and refresh rate/s of their single or dual monitor setups. Then the desired ‘webcast’ resolution (usually 640x480 or similar) and inputs the values into the “Monitor Settings” part of the script. Then an application is made and presto!

When activated using a single monitor, the script brings up a prompt to ask if the user wishes to enter ‘Webcast’ mode. If ‘Yes’ is clicked, then Stickies and Dashboard will be closed if they are open (to avoid them getting messed up by the resizing), the screen changes to SD resolution and the window of the application last being viewed is reset to full-size on the screen. Lastly, ShadowKiller is activated to conserve Video Ram, aiding in playback consistency. When done, and the script is reactivated, then the screen returns to normal, the program window is re-maximized and the window shadows come back on.

With dual monitors, the process is very similar accept that the prompt asks which monitor to change.

Thanks so much to everyone who helped me to finally get this working. Applescript is AWESOME!! Now onto learning Ubuntu Linux scripting!! :smiley:



-- ---------------------
-- Monitor Settings
-- ---------------------


-- Single Monitor/Monitor 1 - Full Horizontal Resolution:
set scr1fX to "1056"
-- Single Monitor/Monitor 1 - Full Vertical Resolution:
set scr1fY to "792"
-- Single Monitor/Monitor 1 - Full Refresh Rate ** : 
set scr1fR to "96"

-- Monitor 2 - Full Horizontal Resolution:
set scr2fX to "1024"
-- Monitor 2 - Full Vertical Resolution:
set scr2fY to "768"
-- Monitor 2 - Full Refresh Rate ** :
set scr2fR to "75"

-- Single Monitor/Monitor 1 - Webcast Horizontal Resolution:
set scr1wX to "640"
-- Single Monitor/Monitor 1 - Webcast Vertical Resolution:
set scr1wY to "480"
-- Single Monitor/Monitor 1 - Webcast Refresh Rate ** :
set scr1wR to "154"

-- Monitor 2 - Webcast Horizontal Resolution:
set scr2wX to "640"
-- Monitor 2 - Webcast Vertical Resolution:
set scr2wY to "480"
-- Monitor 2 - Webcast Refresh Rate ** :
set scr2wR to "75"

--   ** Note: Refresh rates can be left blank  ""  if unknown or none applicable (i.e. an ADC LCD monitor).


-- --------------
-- Script Code
-- --------------


-- End of Script Tidy-Up.

on monitorTidyUp()
	-- Disables Shadowkiller.
	launch application "ShadowKiller"
	delay 1
	-- Resize Apps (requires RightZoom).
	tell application "System Events"
		repeat with appWindow in (every application process whose visible is true)
			click (second button of every window of appWindow)
		end repeat
	end tell
	-- Exit Script.
	error number -128
end monitorTidyUp



-- Gets current screen resolutions from cscreen.
do shell script "cscreen"
set screenResolution to the result


--
-- 'Single Monitor' mode.
--

if screenResolution contains "1 display found" then
	if screenResolution contains scr1wY then
		-- Returns Monitor to normal if in Webcast (low-res) Mode.
		do shell script "cscreen -s 1 -x " & scr1fX & " -y " & scr1fY & " -r " & scr1fR & ""
		-- Tidy Up.
		monitorTidyUp()
		
	else
		
		-- If Monitor is normal, prompts user to activate Webcast Mode (optional 'Cancel' to quit).
		display dialog "                     Enable Webcast Mode?" buttons {"Yes", "Cancel"}
		set screenChoice to button returned of the result
		if screenChoice is "Yes" then
			-- Shutdown Stickies if open to avoid repositioning.
			quit application "Stickies"
			delay 0.5
			--Disables Dashboard.
			do shell script "killall Dock"
			delay 0.5
			--webcast mode.
			do shell script "cscreen -s 1 -x " & scr1wX & " -y " & scr1wY & " -r " & scr1wR & ""
			-- Tidy Up.
			monitorTidyUp()
			
		else
			-- Quits script if user selects 'Cancel'.
			error number -128
			
		end if
	end if
	
	
	--
	-- "Dual Monitor" mode.
	--
	
	-- Returns either Monitor to normal if one is in Webcast (low-res) Mode.
else if screenResolution contains scr1wY or scr2wY then
	do shell script "cscreen -s 1 -x " & scr1fX & " -y " & scr1fY & " -r " & scr1fR & " && cscreen -s 2 -x " & scr2fX & " -y " & scr2fY & " -r " & scr2fR & ""
	-- Tidy Up.
	monitorTidyUp()
	
	
else
	
	
	-- If both Monitors are normal, prompts user to set one of them to Webcast Mode (optional 'Cancel' to quit).
	display dialog "                     Select Webcast Monitor:" buttons {"# 1", "# 2", "Cancel"}
	set screenChoice to button returned of the result
	
	
end if


-- Sets Monitor '1' to webcast mode.
if screenChoice is "# 1" then
	-- Shutdown Stickies if open to avoid repositioning.
	quit application "Stickies"
	delay 0.5
	--Disables Dashboard.
	do shell script "killall Dock"
	delay 0.5
	--webcast mode.
	do shell script "cscreen -s 1 -x " & scr1wX & " -y " & scr1wY & " -r " & scr1wR & ""
	-- Tidy Up.
	monitorTidyUp()
	
	
	-- Sets Monitor '2' to webcast mode.
else if screenChoice is "# 2" then
	-- Shutdown Stickies if open to avoid repositioning.
	quit application "Stickies"
	delay 0.5
	--Disables Dashboard.
	do shell script "killall Dock"
	delay 0.5
	--webcast mode.
	do shell script "cscreen -s 2 -x " & scr2wX & " -y " & scr2wY & " -r " & scr2wR & ""
	-- Tidy Up.
	monitorTidyUp()
	
else
	
	
	-- Quits script if user selects 'Cancel'.
	error number -128
	
end if

Model: MDD Dual 1.42
AppleScript: 2.1.2
Browser: Firefox 17.0 TenFourFox/7450
Operating System: Mac OS X (10.4)