3

After using Applescript to add a new row with data to a Numbers document, I'm trying to save and close the document and then quit Numbers. Using the script below to save, close and quit Numbers works when I run it in an open Script editor window:

save document 1 in "/Users/name/Desktop/Workout.numbers"

close document 1 in "/Users/name/Desktop/Workout.numbers"

activate application "Numbers"
tell application "System Events" to keystroke "q" using command down
end

But it does not work when run as a standalone Applescript App; it seems to stop on saving.

And, as a side note, using the tell block below to quit Numbers acts in the same way; it works when run via the Script Editor, but not in an App:

tell application "Numbers"
    quit
end tell

Why the difference between running in an open Script Editor window and running as an Applescipt App? How can I script Numbers to save close and quit in an Applescript App?

1 Answer 1

4

You need to direct the save command to Numbers app...

This should work for you.

tell application "Numbers"
    save document 1 in POSIX file "/Users/name/Desktop/Workout.numbers"
    delay 0.1
    close document 1 
    delay 0.1
    quit
end tell

Or if you want to make the code a little prettier... This should work also.

set saveToFolder to path to desktop folder as text
set numbersDocName to "Workout.numbers"
set numbersDoc to (saveToFolder & numbersDocName)

tell application "Numbers"
    close document 1 saving yes saving in file numbersDoc
    delay 0.1
    quit
end tell
2
  • 1
    Yeah, those delays come in handy!
    – Monomeeth
    Commented Aug 27, 2019 at 5:05
  • Thanks, the second one works fine. I didn't realize Numbers had to be aware of the file to be saved. Commented Aug 27, 2019 at 14:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .