Chain Powerpoint presentations

Hi,
I was trying to get a symposium here to run more slickly, with none of that faffing about as one speaker hands over to another, plugging in USB sticks and fumbling opening Powerpoint etc.

To that end, I devised a script which will take charge of the entire shebang and run a whole day’s programme from a single (I expect very big!) memory stick.

It simply finds all the Powerpoint presentations in a folder (and/or in subfolders) and runs them one after another in sequence, waiting at the end of each presentation (or if someone hits ESCAPE) to load up the next one. You put each presentation into a numbered folder and put the numbered folders into a master folder. The application/script also hides other applications and pretties up the desktop background.

Potential improvements are adding a handler for Keynote and Quicktime files and retaining the original desktop settings to restore them at the end.

It responds to drag and drop (when saved as a stay open application), and will pick a default folder in the same container, otherwise it asks for the folder location.



(* Chaînette - CHAIN PRESENTATIONS

	Purpose: To allow a series of speakers to present Powerpoint presentations which automatically load in a defined sequence.
	
	Application notes:
	Presentations. 
	Place all presentations and their resources in separate folders numbered in sequence, e.g. 01-Speaker 1, 02-Speaker 2, 03-Speaker3 etc. Place these presentations in a master folder.
	If the master folder is in the same container as this application/script, and the folder is called Presentations, then the script will run automatically. The application also responds to dropped folders and will present a choose folder dialog if it needs to.
	
	Background image. 
	The script will change the desktop background to either the file "backdrop.jpg" in the Presentation folder or the system default dark grey.
	
	Notes.
	All open application windows should minimize in order to minimize "flashing" and showing of underwear between presentations.
	
	At the end of a presentation (or when the show stops running for any reason), the current presentation will remain open in order for speakers to refer back to their presentation in the event of questions. The open presentation closes when the user responds OK to open the next presentation.
	
	After all presentations in the folder have finished, the application will quit in order to allow confusion-free rerunning of the show. (If the application remains open, then the startup choice of folders doesn't happen).
	
	Development.
	One could add a handler for Keynote applications or Quicktime movies as well, allowing a heterogenous environment for speakers.
	
    © Grant Wray 2011
	
*)

on run {}
	tell application "Finder"
		activate
		set myLocation to container of (path to me)
		try
			set theRoot to folder "Presentations" of myLocation
		on error
			set theRoot to choose folder default location myLocation
		end try
	end tell
	main(theRoot)
end run

on open names
	set pathNamesString to "" -- Start with empty text string.
	repeat with i in names
		main(i)
	end repeat
	return
end open

on showPowerPoint(fileName, lastPresentation) -- Handler for Powerpoint files
	tell application "Microsoft PowerPoint"
		try
			close lastPresentation -- This will error for the first presentation
		end try
		try
			open fileName
			set theOpenedPresentation to (first presentation whose full name = (fileName as string))
			run slide show slide show settings of theOpenedPresentation
			activate
		end try
		set r to true
		repeat until r is false -- Hold in a loop until the presentation stops running.
			try
				set r to slide state of slide show view of slide show window of active presentation is slide show state running
			on error
				exit repeat
			end try
			delay 1
		end repeat
		set lastPresentation to theOpenedPresentation
	end tell
	return lastPresentation
end showPowerPoint

on tidyUp(theRoot) -- Clean up the computer's screen
	set theBackupBackdrop to "Macintosh HD:Library:Desktop Pictures:Solid Colors:Solid Gray Dark.png"
	set theBackdrop to ((theRoot as text) & "backdrop.jpg")
	set theBackdropExists to false
	tell application "Finder" to if exists theBackdrop then set theBackdropExists to true
	log {theBackdrop, theBackdropExists}
	if not theBackdropExists then set theBackdrop to theBackupBackdrop
	tell application "System Events" -- Set desktop background
		tell current desktop
			set change interval to 0
			set picture rotation to 0
			set random order to false
			set picture to theBackdrop
		end tell
	end tell
	tell application "System Events" -- Minimize visible application windows
		set activeProcesses to name of every application process whose (visible is true)
	end tell
	set tmpWindows to 0
	repeat with processCounter in activeProcesses
		tell application processCounter
			try
				activate
				set tmpWindows to count windows
			on error
				set tmpWindows to 1
			end try
		end tell
		if tmpWindows > 0 then
			tell application "System Events"
				tell application processCounter
					repeat tmpWindows times
						try
							keystroke "m" using command down
						end try
					end repeat
				end tell
			end tell
		end if
		set tmpWindows to 0
	end repeat
	tell application "Microsoft PowerPoint" -- start Powerpoint if it's not running and close any existing slideshows if it is.
		try
			exit slide show
		end try
		try
			close every presentation saving no
		end try
	end tell
	return
end tidyUp

on displayAlert(folderName, fileName) -- Wait for the OK to go on to the next show.
	activate
	set alertResult to display alert ¬
		"Ready to load next presentation." & return & ((name of folderName as text) & " - " & (name of fileName as text)) buttons {"Stop", "Skip", "OK"} ¬
		default button "OK" cancel button "Stop" -- giving up after never
end displayAlert

on main(theRoot)
	tell application "Finder"
		activate
		my tidyUp(theRoot)
		set lastPresentation to false
		set theFolders to every folder of theRoot
	end tell
	repeat with folderName in theFolders
		tell application "Finder"
			set thePresentations to (every item of folderName whose kind is "Microsoft PowerPoint presentation" or kind is "Microsoft PowerPoint 97 - 2004 slide show" or kind is "Microsoft PowerPoint 97-2004 presentation") -- This line could be modified to include Keynote or any other presentation file, provided there is a handler that responds appropriately and the App is scriptable. 
		end tell
		repeat with fileName in thePresentations
			set alertResult to displayAlert(folderName, fileName)
			if button returned of alertResult is not "Skip" then
				if ((kind of fileName is "Microsoft PowerPoint presentation") or ¬
					(kind of fileName is "Microsoft PowerPoint 97 - 2004 slide show") or ¬
					(kind of fileName is "Microsoft PowerPoint 97-2004 presentation")) ¬
					then
					set lastPresentation to my showPowerPoint(fileName, lastPresentation)
					(*
					else if ((kind of fileName is "Other kind") or ¬
						(kind of fileName is "Other kind slide show") or ¬
						(kind of fileName is "Other kind presentation")) ¬
					then
					set lastPresentation to my newHandler(fileName, lastPresentation)
					*)
				end if
			end if
		end repeat
	end repeat
	activate
	set alertResult to display alert ¬
		"End of presentations." & return buttons {"OK"} ¬
		default button "OK"
	tell me to quit
end main