Saving a Numbers Document with Name Taken From a Cell On The Sheet
Ok, this is weird, and admittedly, I'm no AppleScript expert, but I have had a working AppleScript Workflow running as a service in Numbers, but when I moved it from my MBP running Sequoia 15.71 to an Apple Studio running the current version of Tahoe it worked for a short period then started generating an error.
Basically, the Service (AppleScript) grabs the name from a cell that exists on a table on the second sheet and saves it in a folder on the desktop labeled: "Expense Reports". It works flawlessly on the MBP. On the Mac Studio it throws this error:
"The document "untitled.numbers" could not be exported as "Henry Smith". You don't have permission. To view or change permissions, select the item in the Finder and choose File > Get Info"
Then it throws some other error afterwards about "Apple EventHandler failed. . . "
There's probably a "best practice" step I'm missing in my script. I'm just wondering if there's a way to explicitly grant the necessary access to the save location within the script itself to avoid the error, or perhaps there's something incorrect within the code itself.
The code that is working on the MBP is:
on run {input, parameters}
tell application "Numbers"
tell the front document
set active sheet to sheet 2
tell the active sheet
tell the first table -- Where the Name exists
set cellValue to the value of cell "B3" -- Get the name of the person on the report
if cellValue is not missing value then
display dialog “Expense Report For: " & cellValue & " Created!”
tell application "Numbers"
-- Referencing the front document in Numbers App
set theDocument to the front document
-- Access the second sheet and first table
tell the second sheet of theDocument
tell the first table -- Where the name should exist
set cellValue to the value of cell “B3”
-- Get the name of the person on the report
end tell
end tell
-- Define the save location and filename
set savePath to ("Macintosh HD:Users:MAIN_WORK:Desktop:Expense Reports:" as text) & cellValue & ".numbers"
-- Save the document with the derived filename
save theDocument in file savePath
end tell
else
display dialog "Cannot Save! No member name present!"
end if
end tell
end tell
end tell
end tell
return input
end run
I'd say the script is simple enough, and if anyone here can help me out, that would be great. Feel free to clean it up hopefully fix the errors.
Thanks in advance!