Numbers won't load file directed by AppleScript

I am trying to get around the flaw in Number's that won't allow links to external files. I presently have to cut and paste 20 files a day into a spreadsheet and would like to automate the process. I have tried utilizing code that I have found on the web but I can't seem to get it to work. I am not a software guy and a am a newbie to this. The problem is that the Numbers app cant open the input file as directed by the AppleScript code.


I keep getting the following error:

error "Numbers got an error: Can’t get document \"/Users/bill/Documents/test.csv\"." number -1728 from document "/Users/bill/Documents/test.csv"


The path is definitely correct and I have tried running the code with the files already open. Any help would be appreciated. I don't want to have to buy Excel.


The code is as follows:

set theDefaultFolder to POSIX file "/Users/billseton/Documents"

property src : {d:"/Users/bill/Documents/test.csv", s:"Sheet 1", t:"Source"}

property tgt : {d:"/Users/bill/Documents/DailyBuys.numbers", s:"Sheet 1", t:"Target"}

tell application "Numbers"

--vList is a "list of lists" - a two-dimensional array

set vList to document (src's d)'s sheet (src's s)'s table (src's t)'s rows's cells's value

tell document (tgt's d)'s sheet (tgt's s)'s table (tgt's t)

repeat with r from 1 to count rows

repeat with c from 1 to count columns

set row r's cell c's value to vList's item r's item c

end repeat

end repeat

end tell

end tell


iMac 21.5″, macOS 12.7

Posted on Mar 2, 2024 11:41 AM

Reply
2 replies

Mar 2, 2024 12:24 PM in response to Bill0564

You’re headed for two issues here: spreadsheets make poor databases, and that AppleScript gets gnarly much past scripting GUI apps.


Here, I’d use a database and not a spreadsheet, and would use a scripting language or tool and not AppleScript.


I’d then export the database data you need into a spreadsheet, when you need to view or review the data.


If you want to continue on the path you are on, then see if adding Numbers to Accessibility gets past the -1728 error:


Allow accessibility apps to access your Mac - Apple Support


Mar 4, 2024 4:04 AM in response to Bill0564

Can you give more specifics? Do you have to paste values from 20 csv files into one Numbers document? Or 20 other Numbers documents into one document? Do you need all the values in one table? Or will the values from each file go in a separate table?


AppleScript, of course, is a scripting language. It can be slow and verbose and purist coders like to look down on it. But it can be a good solution for a task like this where you need to automate a daily task in an app like Numbers that has reasonably extensive AppleScript support.


This may not be too difficult. But more specifics are needed on exactly what you are trying to do.


SG

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Numbers won't load file directed by AppleScript

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