Trouble clicking "Save As..." menu item

Why does the script below, which works with the Open and Close commands in the same menu, for example, fail at the same level with the “Save As…” item?

Substitute “New from Clipboard” or “Close” for example, in place of “Save As…” and it works fine. But “Save As…”? Can’t get it.

I want to batch a number of saves through Preview but I can’t even get to the dialog. Thanks for any help.

tell application "System Events"
	tell process "Preview"
		set frontmost to true
		delay 2
		click menu item "Save As..." of menu 1 of menu bar item "File" of menu bar 1
	end tell
end tell

Hi,

a very common misunderstanding
The dots are not just dots, it’s a single character called horizontal ellipsis (option semicolon on a US keyboard)

I prefer this syntax:

activate application "Preview"
tell application "System Events"
	tell process "Preview"
		click menu item "Save As." of menu 1 of menu bar item "File" of menu bar 1
	end tell
end tell

Probably because your 3 dots “…” are three periods instead of one option-semicolon (an ellipsis) “.”

Oops – Stefan beat me to it.

The answer (to myself) is to click item 7. I’d still like to know if there’s a way to use naming when there’s an ellipsis. I notice “Open…” and Import Image…" don’t work either.

something like this


activate application "Preview"
tell application "System Events"
	tell process "Preview"
		click (get 1st menu item of menu 1 of menu bar item "File" of menu bar 1 whose name begins with "Open")
	end tell
end tell

OK, I’m into the dialog but I still can’t click the “Save” button.

Thanks for the help to this point!

I Still can’t click the “Save” button n the dialog.

Here’s another way into the “Save As…” dialog, but how do I then click the Save button in the dialog?

Thanks for the help!

tell application “Preview”
activate
end tell

tell application “System Events”
tell process “Preview”
tell menu bar 1
tell menu bar item “File”
tell menu “File”
click menu item 9
click button “Save” of window “Untitled”
end tell
end tell
end tell
end tell
end tell

try this


activate application "Preview"
tell application "System Events"
	tell process "Preview"
		click menu item "Save As." of menu 1 of menu bar item "File" of menu bar 1
		repeat until exists sheet 1 of window 1
			delay 0.5
		end repeat
		click button "Save" of sheet 1 of window 1
	end tell
end tell

Stefan,

Thanks.

Sheets are new objects for me. Just getting started in AppleScript.

UI scripting is at least level two of AppleScript.
It’s better to learn the basics first :wink:

Stefan,

I might as well go for it!. I haven’t tried it yet, but any advise or references on filling the file name and jpeg quality fields in the dialog?

Thanks again and have a great holiday!

this should do it


activate application "Preview"
tell application "System Events"
	tell process "Preview"
		click menu item "Save As." of menu 1 of menu bar item "File" of menu bar 1
		repeat until exists sheet 1 of window 1
			delay 0.5
		end repeat
		tell sheet 1 of window 1
			set focused of text field 1 to true
			keystroke "newName" -- text field name
			set value of slider 1 of group 1 to 0.2 -- (Qualitiy slider, values from 0.0 to 1.0)
			click button "Save"
		end tell
	end tell
end tell

Thanks for the help.

This works great to the selected folder, but how do I save it to a folder nested further in?

I’ve tried double click but so far without success.

Best Regards