Numbers - Export to CSV - Save As step

Hi there,

I’m attempting to write a script that exports the current active document as a CSV. I’ve written most of the code now, but I can’t do the final step of entering a value into the box in the Save As… screen.

At the moment, I’d just like to save the doc as “test” until I finish the rest of my project.

This is what I have so far:

activate application "Numbers"
delay 1
tell application "System Events"
	tell process "Numbers"
		click menu item 3 of menu 1 of menu item "Export To" of menu 1 of menu bar item "File" of menu bar 1
		delay 2
		keystroke return
	end tell
	delay 2
	set value of text field 1 of group 1 to "test"
end tell

Cracked it! I got the file to save using the following code:

activate application "Numbers"
delay 1
tell application "System Events"
	tell process "Numbers"
		click menu item 3 of menu 1 of menu item "Export To" of menu 1 of menu bar item "File" of menu bar 1
		delay 2
		keystroke return
	end tell
	delay 2
	tell window "Save As"
		keystroke "test"
		keystroke return
	end tell
end tell

There is no need to use GUI scripting.

set thePath to ((path to desktop as text) & "essai.csv") as «class furl»

--close access (open for access thePath) # required for 10.12 thru 10.12.3
tell application "Numbers"
	export document 1 to thePath as CSV
end tell

Yvan KOENIG running Sierra 10.12.4 in French (VALLAURIS, France) mercredi 12 avril 2017 15:11:21

Ah thank you Yvan, this is far more efficient!