Skip to content

Instantly share code, notes, and snippets.

@timlien
Last active April 8, 2021 07:02
Show Gist options
  • Save timlien/f478b891289c64ea2f50dc37716aebae to your computer and use it in GitHub Desktop.
Save timlien/f478b891289c64ea2f50dc37716aebae to your computer and use it in GitHub Desktop.
Export mac numbers file into csv format with apple script
#!/usr/bin/osascript
on run argv
set theFilePath to POSIX file (item 1 of argv)
set theFolder to theFilePath as alias
tell application "System Events" to set theDocs to theFolder's items whose name extension = "numbers"
repeat with aDoc in theDocs
set docName to aDoc's name as text
set exportName to (theFolder as text) & docName
set exportName to exportName's text 1 thru -8
-- set exportName to (exportName & "csv") -- append .csv to directory name
tell application "Numbers"
launch
open aDoc
delay 3 -- may need to adjust this higher
export front document to file exportName as CSV
end tell
end repeat
end run
@studiofuga
Copy link

That worked pretty fine, thanks. Only there's no extension in the exported file, so you may want to add a

set exportName to (exportName & "csv")

just between lines 17 and 18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment