With my code buddy ChatGPT I’ve written a few handlers to read and write to a plist. It’s a half-way house effort to replace a large series of defaults reads but not to go the full Stanley with the prefsLib and its commitment to storing the plist in Preferences.
When I run it an error terminates execution with this message:
fileURLWithPath_(“/Users/limpet/Library/Application Support/delta/quovadis.plist”)
“handlePref failed: NSURL doesn’t understand the “fileURLWithPath_” message.”
The offending line is in this readPlist() handler which is called by handlePref() but it doesn’t show any _
ChatGPT says “you’re still seeing fileURLWithPath_() which means AppleScript is calling the selector with a trailing underscore, which only happens if the method is being incorrectly called with the wrong syntax somewhere earlier in your script, or if it was compiled that way and is cached.”
ChatGPT wants me to solve the cache problem by copying and pasting the code into a brand new file. I think that quitting and restarting SD achieves the same result. Nonetheless the problem persists.
There is only one place that fileURLWithPath is called in my script and that is in here:
on readPlist()
set theNSURL to current application's NSURL's fileURLWithPath:(plistPathPOSIX)
set theData to current application's NSDictionary's dictionaryWithContentsOfURL:theNSURL
if theData is missing value then
return {}
end if
return theData as record
end readPlist
I’m at an impasse here; ChatGPT has run out of ideas, and so have I.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
use sdbScript : script "supportEsseQuamVidere.scptd"
property db : sdbScript's NaMgAlSiPSClAr
the child script, which does all the work has:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
script NaMgAlSiPSClAr
All I can suggest is that (a) ChatGPT is quite wrong about the underscore, and (b) using script objects inside script libraries feels a bit too adventurous for my tastes.
If I run this script:
use AppleScript version "2.4" -- Yosemite (10.10) or later
-- use framework "Foundation"
use scripting additions
set plistPathPOSIX to POSIX path of (path to application support from user domain)
set theNSURL to current application's NSURL's fileURLWithPath:(plistPathPOSIX)
The error I get is:
NSURL doesn’t understand the “fileURLWithPath_” message.
Look familiar?
So I suspect that somehow you’re losing the Foundation inheritance.
FWIW here’s what ChatGPT said when I pointed out that removing the Script object definition worked:
Why Removing the Script Object Fixed It
When using script … end script, AppleScript:
• Wraps methods and properties in a scope that can interfere with AppleScript-ObjC selectors.
• Sometimes misinterprets Objective-C selectors like fileURLWithPath: as fileURLWithPath_, especially if the method is called indirectly or if the syntax isn’t precisely clean.
This can result in:
• -suffixed selectors that don’t exist (fileURLWithPath)
• Silent substitution of method calls
• AppleEvent handler errors like errAEEventNotHandled
What to Do Going Forward
• For AppleScript-ObjC-heavy code, prefer writing handlers at the top level of the script (outside a script block).
• If you do use script … end script for modularity:
• Avoid calling Cocoa methods inside it unless you’re fully confident in how AppleScript compiles and scopes them.
• Test selectors carefully — even valid-looking ones can be interpreted differently inside a script object.