Wednesday, June 28, 2017

#1 2017-04-12 05:15:01 am

Adam239
Member
Registered: 2016-10-13
Posts: 54

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:

Applescript:

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


running Sierra 10.12.4

Offline

 

#2 2017-04-12 08:01:15 am

Adam239
Member
Registered: 2016-10-13
Posts: 54

Re: Numbers - Export to CSV - Save As step

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

Applescript:

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


running Sierra 10.12.4

Offline

 

#3 2017-04-12 08:11:37 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3059

Re: Numbers - Export to CSV - Save As step

There is no need to use GUI scripting.

Applescript:

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

Offline

 

#4 2017-04-12 08:49:43 am

Adam239
Member
Registered: 2016-10-13
Posts: 54

Re: Numbers - Export to CSV - Save As step

Ah thank you Yvan, this is far more efficient!


running Sierra 10.12.4

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.036 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)