I’ve got an error I found a simple fix for, but I can’t understand the cause at all, if anyone could enlighten me.
The script involved and associated libraries run way too long to post here, so I need to try to abstract the bits I see as relevant… except I have no idea what’s relevant… so ask for further info.
There’s a handler. Inside the handler it reads the contents of a text file like this:
set wordList to read file ((path to home folder as text) & [rest of path here])
This works fine by itself. Or I can copy the whole handler out into another script and call it. It runs fine. Or I can copy a huge block of code around the call out into another script; still runs fine.
But when it’s run inside the actual script in question, the script errors on that line with:
“Can’t make current application into type file.”
So I figure something else is using the term “file” or something…
The handler it’s in doesn’t have that inside a tell or anything, but the entire handler is called inside a
tell application “Adobe Photoshop”
tell the current document
But in my experience, a handler called from inside a “tell” doesn’t carry over the tell. And I’ve tested it inside all the “tell” statements in a broken-out script and it still works.
Then I thought it might be something ASObjC related redefining “file” in this context. The script’s got the following headers:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
use script "Dialog Toolkit ROT"
But I added all that to my broken-out copy, and it still runs fine.
So, what makes it work is simply putting that line inside a tell…
tell application "System Events" to set wordList to read file ((path to home folder as text) & [rest of path here])
Now it works and doesn’t get the error… but why is this necessary? What other code in my script could be causing this to require being inside a “tell” to make it work?