Saving a Numbers file

I’m new to Applescript, please pardon something that may be an elementary question. I have searched here and other places and have not found an answer.

I’m building a script that compiles a number of data fields from another application and puts them in Numbers. That works just fine. However, I want to save the Numbers file I have created automatically with no input from the user. The name of the file will be the date and time it was created.

I haven’t found a way to get past the “Save As” dialog box. Is it possible? The script will be running at all times of day and night, and obviously I don’t want the user to have to get out of bed to save the file.

Thanks, Tom Jeffries

this is what works for me. You will need to change the desktop to where you want the file to be copied. Also, I had to remove the :'s from the time in order for the file path to work. Somebody might have a better solution.

set {year:Currentyear, month:Currentmonth, day:Currentday} to (current date) -- Gather the date parts only of current date
set theDate to Currentmonth & " " & Currentday & " " & Currentyear as string -- Rejoin the date parts into a string
set theTime to time string of (current date) -- Get the time string
set AppleScript's text item delimiters to ":"
set theTimeParts to text items of theTime
set AppleScript's text item delimiters to "."
set theTime to items 1 thru -1 of theTimeParts as string
set AppleScript's text item delimiters to ""

set FileName to (theDate & " " & theTime) & ".numbers" as string


tell application "Numbers"
	set DestinationFile to (path to desktop as string) & FileName as string
	save document 1 in DestinationFile
end tell

Many thanks- that does the trick.

To build the name I use an other scheme.


set FileName to do shell script "date +%Y%m%d_%H%M%S.numbers"

tell application "Numbers"
	set DestinationFile to (path to desktop as string) & FileName as string
	save document 1 in DestinationFile
end tell

Yvan KOENIG (VALLAURIS, France) jeudi 9 juin 2011 11:38:27