GUI scripting basics - help!

I’m trying to script Preview, which doesn’t have a Dictionary.
I’m trying to use GUI scripting with some basics I picked up from “The Missing Manual” and from Apples website.
Could someone let me know either why this doesn’t work:

tell application "Preview"
	activate
end tell
tell application "System Events"
	tell process "Preview.app"
		tell menu bar 1
			tell menu item "Save As..."
				tell sheet 1
					tell group 1
						tell pop up button 1
							tell menu
								click menu item "PDF"
								end tell
							end tell
						end tell
					end tell
				end tell	
			end tell
		end tell
	end tell
end tell

Or, where I can find out a good way to make it work.
Thanks! AB

Tell us what it’s supposed to do for you.

Thanks for quick reply -
This is opening a jpeg document, Saving As a PDF document and closing the document.

Take your lead from this previous thread which uses Image Events (built-in to Tiger and perhaps Jaguar too).

Aha, Image Events App - very useful, thanks for pointing me there.

In the dictionary, they list:
save‚v : Save an image to a file in one of various formats
save reference : the object for the command
[as BMP/JPEG/JPEG2/PICT/PNG/PSD/QuickTime Image/TIFF] : file type in which to save the image ( default is to make no change )

No PDF on the this though. Is this what Preview would be using?

Very frustrating. Image Events will convert among all the rastered image types but won’t go to pdf which is like a bit map type (I think) rather than a vector file. At the same time, converting anything to be printed to a saved PDF is an option. Surely there’s an engine somewhere to do that, but I can’t find it.

Actually, it is vector based.

Hi,

ui scripting the Print window to save as pdf can be done. You end up with a save dialog, however you can’t ui script the location on where to save the pdf.

What I like to do is change the “Save As PDF…” to a popup button using PDF Workflow which is a built-in option to all users.

http://www.apple.com/applescript/print/

Switching the button to popup allows you to select a menu item which saves your pdf to a certain folder or may pass a reference of the pdf located in a hidden folder to a script. You sould probably use the first option and save to a predesignated folder where your script can do whatever it wants with the new pdf.

Your’s is a common post and may still be here in discussions where I showed someone how to do it.

I’m thinking that there was a way to do this with unix also, but can’t remember.

Note I los all my new scripts, so haven’t posted an example.

gl,