I have been using an AppleScriptObjC script that creates a Numbers document that inserts a jpg image of a signature and has worked for some time. I recently changed to a new MacBook running Monterey and now the script will no longer compile because of the jpg file as alias.
I understand that Apple has changed to APFS which does not support alias files but I cannot find how to change the script to work. Any help would be gratefully received as I now have no idea how to achieve this. (Sorry couldn’t find how to format the script)
property cpSignature : alias “Macintosh HD:Users:Ours:Documents:Cats Protection:Branch Information:Signature Sue.jpg"
tell application “Numbers”
activate
set thisDocument to make new document with properties {document template:template “Blank”}
–
tell thisDocument
tell active sheet
delete every iWork item
set thisImage to make new image with properties {file:cpSignature, position:{394, 525}, width:90}
end tell
end tell
end tell
hello,
Your script is not AppleScriptObjC but plain AppleScript. But I will try help you here, anyway. I think, you can fix the problem with coercion Alias Reference >>> File Reference. Because in the Numbers dictionary is recommended File References for image’s files:
-- property cpSignature : choose file of type "public.image"
property cpSignature : alias "Macintosh HD:Users:Ours:Documents:Cats Protection:Branch Information:Signature Sue.jpg"
tell application "Numbers"
activate
set thisDocument to make new document with properties {document template:template "Blank"}
set cpSignature to a reference to file (cpSignature as text) -- Coercion Alias to File Reference
--
tell thisDocument
tell active sheet
delete every iWork item
set thisImage to make new image with properties {file:cpSignature, position:{394, 525}, width:90}
end tell
end tell
end tell
Thanks for your reply, the lines of code shown are from a longer ApplescriptObjC script compiled with Xcode that failed with the error
“AppleEvents failed to encode extension for /Volumes/Macintosh HD/Users/Ours/Documents/Cats Protection/Branch Information/Signature Sue.jpg, err=No such file or directory/2”
I made the change you suggested but it failed with the error
" Can’t make alias “Macintosh HD:Users:Ours:Documents:Cats Protection:Branch Information:Signature Sue.jpg” into type text. (error -1700)"
Is there anything else I can try?
The error messages you provided hint that you have not spelled the alias correctly. To get the correct alias, run the following code, select an image file, and copy the result:
set cpSignature to (choose file)
Excellent, now all working as expected but I’m curious as to why a working script failed after updating to Monterey.
The original file path was
“Macintosh HD:Users:Ours:Documents:Cats Protection:Branch Information:Signature Sue.jpg”
but using choose file the file path is now
“Macintosh HD - Data:Users:Ours:Documents:Cats Protection:Branch Information:Signature Sue.jpg”
The “- Data” is this to do with APFS?
Once again, thanks for your help, it’s saved my sanity!!