Microsoft PowerPoint Trouble

Hi there,

I’m new to AppleScripting and having trouble doing two things that I think should be fairly simple.

Here is what I need to do in my script.

  1. Open PowerPoint
  2. Close the initial New Project window that pops up or use this window to take care of step 3.
  3. Run the open command so that the user can select his presentation to open.
  4. Save his selected presentation as a .GIF or .JPEG (either will do)
  5. Close PowerPoint.

Steps 1 and 5 are very easy and I’ve had no problems with them.
I haven’t tried step 3 yet because I’ve been stuck elsewhere.
My big problem is with steps 2 and 4.

I’ve tried turning on GUI scripting w/ assisted devices, but for some reason, it doesn’t want to work at all on any of the school’s computers except for limited functionality within finder. This unfortunately means that I have no Mac that is accessible to me where GUI Scripting works.
Strictly speaking for step 4, I am aware that there is a documented “save as” command for PowerPoint. However, it only allows you to save as .ppt, pdf, html, or some other strange format. It is not that PowerPoint doesn’t have the ability to save as an image, it is just that the feature is not defined in the PPT dictionary. Luckily, if worse comes to worse, I think I can just save as HTML and use the images it generates for that. This does leave me with a lot of junk files however.

If anyone could help me with this problem, or lead me to how this would be coded, I would be VERY appreciative. Thanks for your time and happy scripting.

Sincerely,

Chad

Hi Chad, sadly I don’t think you are going to be able to accomplish your goal here. After some time poking around it looks like Microsoft did not implement Apple’s accessibility technology correctly. Take the script below.

set ps_file to choose file with prompt "Please select the PowerPoint file to open"
set {full_name, ext} to {name, name extension} of (get info for ps_file)
set short_name to text 1 through -((count of ext) + 2) of full_name
tell application "Microsoft PowerPoint"
	activate
	tell application "System Events"
		tell process "PowerPoint"
			if exists window "Project Gallery - New" then
				click button "Cancel" of window "Project Gallery - New"
				delay 2
				tell application "Microsoft PowerPoint" to close presentation 1
			end if
		end tell
	end tell
	open ps_file
	tell application "System Events"
		tell process "PowerPoint"
			click menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
			click pop up button 1 of UI element 1 of UI element 1 of UI element 8 of sheet 1 of window full_name
			click menu item "JPEG (Joint Photographic Experts Group)" of menu 1 of pop up button 1 of UI element 1 of UI element 1 of UI element 8 of sheet 1 of window full_name
		end tell
	end tell
end tell

Everything looks good so far that it even selects the JPEG format from the pop up, but this is actually where the script fails as well. That value itself is not being selected so much as being shown. Notice that if you do it by hand the append extension goes away and the file name changes. For somereason I can’t find a way to make the JPEG (or gif for that matter) actually become the selected value rather then merely the shown value.

The reason, btw, we had to try to GUI script this is that GIF/JPEG are special file formats not accessible through PowerPoint’s save command.

Sorry.

Wow James!

Excellent work, and I really do appreciate the help you’ve given. I’ll try the script out ASAP. I believe with what you have provided me and the Save As HTML work-around i discussed, I believe my problem is solved. I’m not sure you can recognize how much of a life saver you have been and I am very greatful to you.

Thanks again,

Chad

P.S. I’ll keep this thread up-to-date with project progress and let everyone know how it all turns out.

Hi Chad,

I actually missed your part about the HTML as being an option LOL. Anyways I modified the script to use my beginning portion, but then save to HTML. The script then goes on to delete irrelevant files leaving you with a folde on the desktop containing the images.

I only had 1 PowerPoint file to test this with though so it may need some tweaks as I am not 100% sure on how PowerPoint may name files, but hopefully this will give you a good start.

set ps_file to choose file with prompt "Please select the PowerPoint file to open"
set {full_name, ext} to {name, name extension} of (get info for ps_file)
set short_name to text 1 through -((count of ext) + 2) of full_name

set ATID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set file_path to (text 1 thru text item -2 of (ps_file as string)) & ":"
set AppleScript's text item delimiters to ATID

set target_file to file_path & short_name

tell application "Microsoft PowerPoint"
	activate
	tell application "System Events"
		tell process "PowerPoint"
			if exists window "Project Gallery - New" then
				click button "Cancel" of window "Project Gallery - New"
				delay 2
				tell application "Microsoft PowerPoint" to close presentation 1
			end if
		end tell
	end tell
	open ps_file
	save active presentation in target_file as save as HTML
	close presentation 1 saving no
end tell

tell application "Finder"
	delete file target_file
	set slide_path to file_path & short_name & "_files"
	set the_files to every file of folder slide_path
	considering case
		repeat with aFile in the_files
			if name of aFile does not start with "Slide" then
				delete aFile
			end if
		end repeat
	end considering
end tell

Best of luck!