Powerpoint 2011 Running Presentation Cannot Be Fully Activated

I have an AppleScript that starts Powerpoint, opens a presentation, and starts the presentation. This works fine. However, I cannot get AppleScript to fully activate the presentation so that I can simply start advancing slides say with the right arrow key. You must click the actual presentation window and then slides will advance.

Here is the code:


on runPowerPoint()
	set powerpointFile to POSIX path of powerpointFile
	do shell script "open -b com.microsoft.PowerPoint " & quoted form of powerpointFile
	delay 5
	
	tell application "Finder" to activate
	delay 2
	
	ignoring application responses
		tell application "Microsoft PowerPoint"
			activate
			run slide show slide show settings of active presentation
			delay 5
		end tell
	end ignoring
	tell application "Finder" to activate
	tell application "Microsoft PowerPoint"
		activate
		activate its last slide show window
	end tell
end runPowerPoint

Here is the solution I came up with. The problem was in the ignoring statement.

There are issues that I was not able to solve:

  1. I could not find a delay routine that really worked to wait for PowerPoint to start.
  2. I could not find a delay routine that allowed time for the presentation to load.

If AppleScript gets ahead of PowerPoint starting and the loading of the presentation, an error is returned. That is why you see the delays in the script.

Comments appreciated.:cool:


set powerPointFile to (choose file with prompt "Select PowerPoint file:" of type {"ppt", "pptx", "pptm"})

runPowerPoint(powerPointFile)

on runPowerPoint(theFile)
	set theFile to POSIX path of theFile
	
	--Start PowerPoint and load presentation
	do shell script "open -b com.microsoft.PowerPoint " & quoted form of theFile
	
	--Give time for PowerPoint to start
	delay 5
	
	tell application "Microsoft PowerPoint"
		activate
		
		--Give time for presentation to load
		repeat until document window 1 exists
			delay 0.2
		end repeat
		
		--Start the presentation's slide show
		run slide show slide show settings of active presentation
	end tell
end runPowerPoint

Hello.

Good Job!

Here is a way, (UNTESTED, you may have to verify the process name of PowerPoint), to maybe decrease the number of seconds you wait for PowerPoint to be up and running.

tell application id "com.apple.systemevents"
	repeat while true
		set PowerPointUp to (count of (every process whose name is "Microsoft PowerPoint")) > 0
		if PowerPointUp then
			exit repeat
		else
			delay 0.2
		end if
	end repeat
end tell

Works amazingly well!!! Thank You!!!

I simply replaced the delay 5 line with your code and it works like a champ.
:smiley: