Powerpoint to PDF to JPG script

I can’t seem to get this to work properly.

WANT:
Run a script so any .pptx dropped in a folder is converted to a JPG file. I am also ok with it running the batch conversion on a selected folder or selected/filtered Finder items.
Filenames should match the basename of the .pptx file with page numbers before the extension. This IS how it will export from Powerpoint (except for page 1 which is created with NO page number added. Ideally, these would be 2 or 3 digit numbers like 001, 002, 003.

NOW:
I run a script on a folder that converts .pptx to PDF file. I then manually drag the PDF to another folder (PDF to JPEGs) to run the Automator “Render PDF pages to Images” and then to rename finder items to convert the “.jpeg” to “.jpg” (because it bugs me). If I don’t manually move the items the script won’t run properly as a folder action.

Upon completion of the PDF file I would prefer to have it run another folder action (on a subfolder if necessary?) to then convert the PDF to a JPG using the Automator command mentioned but it doesn’t seem to follow that process.

APPLESCRIPT:
Below is a script I found to output a PDF when a .pptx file is dropped on a folder. The script below works ok in creating a PDF. Running this through Automator works fine but ideally, I would prefer it to export the JPGs instead of adding the step of creating the PDF only to convert to a JPG.

  1. Can this be modified to do that?
on run {input, parameters}
	
	tell application "Finder"
		
		set theItems to input
		
		repeat with itemRef in theItems
			
			set theItemParentPath to (container of itemRef) as text
			set theItemName to (name of itemRef) as string
			set theItemExtension to (name extension of itemRef)
			set theItemExtensionLength to (count theItemExtension) + 1
			set theOutputPath to theItemParentPath & (text 1 thru (-1 - theItemExtensionLength) of theItemName)
			
			tell application "Microsoft PowerPoint"
				
				open itemRef
				
				tell active presentation
					
					save in theOutputPath as save as PDF
					close
					
				end tell
				
			end tell
			
		end repeat
		
	end tell
	
end run

As far as I can tell, there isn’t an automator action that converts slides to images, so this uses the intermediate pdf file.

Basically, this takes a single selected pptx, gets its name and converts it to a pdf of the same name on a repository folder. It then splits that into images and names them accordingly. Assumes that selected file has its extension hidden.

[format]get selected finder items (source pptx)
run applescript (tell application “Finder” to set xy to displayed name of item 1 of input; return xy;)
set value of variable (text, value: xy — from above line)
get selected finder items (source pptx again)
open powerpoint presentations (opens in powerpoint)
save powerpoint presentations (save presentations as: File name:‘whatever’, Where:repository, Format: PDF)
get specified finder items (repository folder)
get folder contents (‘whatever.pdf’ of folder ‘repository’)
rename finder items: name single item (name: basename only, to text var from above)
open finder items (should be Preview so that the subsequent line works)
render pdf pages as images (in general, unless your slides are of photographs, use png instead of jpg)
move finder items (as above action defaults to temp folder, this moves them to repository)
rename finder items: make sequential (rename images sequentially, set rules as you see fit)[/format]

There are various ways of doing this but this is relatively straightforward. It should be modifiable to work with a dropped file. Some logic changes would be required for it to work with multiple files (because of the renaming).

I am trying to get PPT slides to JPG so I can find and remove duplicates. I did get it so that AppleScript can open the PPT and export the slides of a file to individual JPGs in one step. Now, I’ll have to add code so that it will do this for all PPTs in a folder I select.

tell application "Finder"
	
	set itemRef to POSIX file "/Users/Shared/Case Study.pptx"
	set itemRef to itemRef as alias
	
	tell application "Microsoft PowerPoint" -- this works using Powerpoint for Mac v16.49
		
		open itemRef
		
		tell active presentation
			
			tell application "System Events"
				tell process "PowerPoint" -- figured out a bunch of this using UI Browser 3.0.2
					click menu item "Export..." of menu 1 of menu bar item "File" of menu bar 1
					click pop up button 2 of sheet 1 of window 1 -- selects the file format field
					perform action "AXShowMenu" of pop up button 2 of sheet 1 of window 1 -- show dropdown list
					
					click menu item 4 of menu 1 of pop up button 2 of sheet 1 of window 1 -- select JPEG
					click button 5 of sheet 1 of window 1 -- click export
					click button "OK" of window 1 -- click Ok on export complete dialog	
				end tell
			end tell
			
			close -- close presentation
			
		end tell -- active presentation
		
	end tell -- app msft PPT
	
end tell

First, I couldn’t get your approach to work but I’m guessing this is because we’re using different versions: I’m running 2011. In case anyone else is also trapped in the past, this is a UI scripting approach that seems to work. It opens a ‘save as…’ dialogue, chooses a format and attempts to save. If the output already exists, it will attempt to replace. Finally, it closes the document.

tell application "Microsoft PowerPoint"
	set wn to name of document window 1
	activate
end tell
tell application "System Events"
	tell process "PowerPoint"
		click menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
		
		set ws to sheet 1 of window wn of application process "Microsoft PowerPoint" of application "System Events"
		tell pop up button 1 of group 1 of ws to perform action "AXPress"
		keystroke "PNG"
		key code 36
		tell button "Save" of ws to perform action "AXPress"
		
		-- if output already exists		
		if exists button "Replace" of sheet 1 of ws then
			tell button "Replace" of sheet 1 of ws to perform action "AXPress"
		end if
		delay 1
		key code 36 -- acknowledge then close document
		click button 3 of window wn of application process "Microsoft PowerPoint" of application "System Events"
		
	end tell
end tell

Browser: Firefox 91.0
Operating System: macOS 10.12

Second, while powerpoint’s applescript functionality is inferior to its office brethren, it does possess an extensive dictionary. So here is a non-ui approach to saving a folder full of ‘pptx’ documents. For each pptx in the finder’s front window, it will create a folder with images in the default save folder. I use PNG here but it is trivial to use other file types.

tell application "Finder"
	set target of Finder window 1 to ((path to desktop) as text) & "points:"
	set sw to insertion location as alias
	
	set pl to files of sw as alias list
	set pla to {}
	repeat with x in pl -- filtre for pptx
		if name extension of x is "pptx" then
			copy contents of x to end of pla
		end if
	end repeat
end tell

tell application "Microsoft PowerPoint"
	activate
	open pla
	
	repeat with dw in pla
		set nn to name of document window 1
		save presentation nn as save as PNG
		close document window nn
	end repeat
end tell

I should note that the script opens all of the documents at once. This may cause issues if there are many docs. That can likely be remedied by moving the open command to within the loop (as in open dw).

Browser: Firefox 91.0
Operating System: macOS 10.12

Hi

Can’t have it working: nothing happens. nothing is extracted whatever the outpath is.

Can you help please ?