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.

duplicate a document in Numbers using Applescript

Hi,


I'm trying to process a series of Numbers documents and copy some of their content into a few version of the document. I can't seem to get the duplication command to work because I can't get the "to location-specifier" phrase to accept a location. I've tried quite a few variation but here's the current version of the program skeleton. I'm showing two different variations I've tried to create a proper "location-specifier". I'm assuming this wants a directory but I've also tried creating a directory/filename as well.


The error I get is "Script Error -- Numbers got an error: Can't make alias "Macintosh HD:Users:username:Desktop:" into type location specifier.


I've tried the first version (the one that's currently commented out) with it ending with "as alias", "as string", "as alias as string", and with nothing after the closing ")". None of those options work. I've also tried having the Finder application executate that command but that doesn't work either.


tell application "Numbers"

activate

set templateDoc to open "/Users/username/Desktop/TestDirectory/Template5.numbers"


tell application "Finder" to set flist to files of folder (POSIX file "/Users/username/Desktop/TestDirectory/WeeklySalesSheets/") as alias list

-- Here's where I try to create the directory to use in the "to location-specifier" phrase of the duplicate command

-- I'm showing two different things I've tried -- and I've tried many other variations.


--set destDir to (POSIX file "/Users/username/Desktop/TestDirectory/WeeklySalesSheets/") as alias


set destDir to (path todesktop)


repeat with fn in flist

set srcDoc to openfn

set destDoc to duplicatetemplateDoctodestDir -- This is the line that fails

set destDoc'sname to (name of fn & " Update")



-- transfer data from srcDoc to destDoc



closesrcDoc

closedestDoc

end repeat



end tell

Thanks,

Dave

Numbers 3.5.2-OTHER, OS X Yosemite (10.10.1)

Posted on Jan 22, 2015 1:36 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 23, 2015 10:20 AM

Your problem is pretty simple - you're using the wrong command.


As far as Numbers.app is concerned, duplicate is used to duplicate an object (such as a chart, a range of cells, etc) within a spreadsheet. It has nothing to do with the file references.

You're probably confused by the fact that the Finder's duplicate command does relate to duplicating files, but that's the inherent problem with AppleScript's dictionary model - each application can define its own commands in whatever way it wants.


The command you actually want is just: save:


set destDoc to save templateDoc in (destDir & name of fn & " Update" as text)

2 replies
Question marked as Top-ranking reply

Jan 23, 2015 10:20 AM in response to DaveAZ

Your problem is pretty simple - you're using the wrong command.


As far as Numbers.app is concerned, duplicate is used to duplicate an object (such as a chart, a range of cells, etc) within a spreadsheet. It has nothing to do with the file references.

You're probably confused by the fact that the Finder's duplicate command does relate to duplicating files, but that's the inherent problem with AppleScript's dictionary model - each application can define its own commands in whatever way it wants.


The command you actually want is just: save:


set destDoc to save templateDoc in (destDir & name of fn & " Update" as text)

duplicate a document in Numbers using Applescript

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