You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

getting AppleScript to Duplicate file from numbers (understanding arguments)

AppleScript is nothing like any other language I have used.. cant figure out what should be so simple.


I am just trying to make a script that would create a local back up of an open document. ( I will reopen the original iCloud version afterwards, but cant get past the saveas)


I tried to use "SAVE <document> IN <Path>" but couldn't figure it out, switched to "DUPLICATE" and am still stuck...


I failed so many times on SAVE, I tried DUPLICATE thinking might be better.

you can see I have tried multiple different things, cant figure out why it keeps failing with different errors that I don't understand. (I commented the error first then the line that throws that error)

These same kinds of things came up with the ability to ?"Save <document> in <path>"




tell application "Numbers"
	set filePath to file of front document
	set the_name to name of front document
	
	set theNewFilePath to "Macintosh HD:Users:MyName:Documents:backups:numbers:"
    --cant make the <filepath> into type location specifier... its literally saying use the 
    -- front document and filepath came from another script 
    -- that makes it for me that i found online and it seems to be the riught format from others  
 --duplicate front document to theNewFilePath

    --Cant get Document whose name is... but it got the name from the front document?
 --duplicate (the document whose name is the_name) to theNewFilePath
	
    --Cant make <filename> into type specifier ... what the heck is this specifier type?
 --duplicate the_name to theNewFilePath
end tell


Any help would be greatly appreciated

Jason

iMac 27″ 5K, macOS 10.14

Posted on Apr 16, 2023 12:56 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 16, 2023 2:44 PM

Turns out after days of working on and off... after posting the above. I finally got it to work... not sure what change I made that made the difference... I took out the "file of" on the document line and added "as string" after the file path (not sure why a string isn't defined with them quotes)....


tell application "Numbers"
	activate
	--create timestamp
	set todaysDate to (current date)
	set DayIs to text -2 thru -1 of ("0" & (day of todaysDate as string))
	set MonthIs to text -2 thru -1 of ("0" & (month of todaysDate as number))
	set YearIs to (year of todaysDate as string)
	set TimeStamp to DayIs & space & MonthIs & space & YearIs

	--get references
	set thisDocument to front document
	set the_name to name of front document

	--create filename and save
	--Only using this in numbers, so the extension will always be 8
	set NewName to text 1 thru ((length of the_name) - 8) of the_name
	set NewName to NewName & "-- " & TimeStamp & ".numbers"
	set theNewFilePath to "Macintosh HD:Users:Myname:Documents:backups:numbers:" & (NewName) as string

	save thisDocument in file theNewFilePath
end tell



Similar questions

1 reply
Question marked as Top-ranking reply

Apr 16, 2023 2:44 PM in response to jaxjason

Turns out after days of working on and off... after posting the above. I finally got it to work... not sure what change I made that made the difference... I took out the "file of" on the document line and added "as string" after the file path (not sure why a string isn't defined with them quotes)....


tell application "Numbers"
	activate
	--create timestamp
	set todaysDate to (current date)
	set DayIs to text -2 thru -1 of ("0" & (day of todaysDate as string))
	set MonthIs to text -2 thru -1 of ("0" & (month of todaysDate as number))
	set YearIs to (year of todaysDate as string)
	set TimeStamp to DayIs & space & MonthIs & space & YearIs

	--get references
	set thisDocument to front document
	set the_name to name of front document

	--create filename and save
	--Only using this in numbers, so the extension will always be 8
	set NewName to text 1 thru ((length of the_name) - 8) of the_name
	set NewName to NewName & "-- " & TimeStamp & ".numbers"
	set theNewFilePath to "Macintosh HD:Users:Myname:Documents:backups:numbers:" & (NewName) as string

	save thisDocument in file theNewFilePath
end tell



getting AppleScript to Duplicate file from numbers (understanding arguments)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.