r/applescript • u/LawrenceSan • Nov 23 '22
Can't edit my AppleScript
I have an old script that I wrote years ago (.scpt file) that worked fine until recently but now is screwing up. It's a complicated script, involving (among other things) my Mac's hosts file and a few different applications… and I think my Mac's setup has changed in some way. I guess I neglected to save it as a plain-text file, I usually don't bother because I normally can open any .scpt file in Script Editor for editing, with no problem.
There's something weird about this script, however. No matter how I try to open it in Script Editor, or the older AppleScript Editor, or Smile… the script runs instead. (And screws up big-time, including freezing whatever script editor I tried to open it in, so I have to force-quit the script editor.)
I've never encountered anything like this before. Why does it refuse to open in an editor? Why does it always run instead?
I can open it in a plain-text editor (like Text Editor or BBEdit) but then it looks like mostly gibberish with just a little English. In fact most of the characters look like Chinese or something! I tried different encodings in BBEdit (UTF-8, UTF-16, etc) but that didn't help. If I just copy & paste the gibberish into Script Editor, it can't make any sense of it either.
I found something to try using command line in the Mac's Terminal: osadecompile … and its man file (instructions) seem dead simple… but even trying that ran the script instead of decompiling it!
What could possibly cause a script to always run when you tell a script editor to open it? Any idea what I can do? Thank you.
View all comments
Show parent comment
1
u/LawrenceSan Nov 27 '22 edited Nov 27 '22
This is true, but actually I'm quite used to Unix-style paths too… in fact I prefer them to the classic Mac HFS paths. I've used the nixy paths in both my (limited) experience with command line, and even more with building websites to run on Apache servers. Actually I never thought of them as "Posix" paths; I've always associated the word Posix with one of the possible syntaxes supported in some implementations of regular expressions. But looking it up now on Wikipedia, I see that "POSIX" (an acronym) is actually a very large family of interface standards that includes all kinds of things, including nixy paths.
I was vaguely aware that nixy pathnames might work in AppleScript, and my first attempt to fix my problem actually used a path in that format, but it didn't work. And I assumed that the boot volume would be considered root, mounted at "/", as you said, although I wasn't sure (I thought that slash might conceivably refer to even lower down, "the computer"). But the path I constructed that way didn't work, and I still don't know why.
The original variable I defined was like this (faux code):
set criticalFolder to "/Library/Application Support/filesForMyApp"
… that didn't work.
But when I replaced that with:
tell application "System Events" to set theStartupdisk to name of startup disk
set criticalFolder to theStartupdisk & ":Library:Application Support:filesForMyApp"
… it did work.
Nonetheless, I'm sure you're right, the problem wasn't the path syntax, I probably made an error elsewhere at the same time.
Your list of System Events locations is very interesting, and looks potentially quite useful. However, I just tried out an item from your list ("utilities folder") in a new blank test script (a .scpt file on my Mac's desktop):
…and Script Editor just highlights "open theFolder" and returns an error:
error "Finder got an error: Handler can’t handle objects of this class." number -10010
Any idea what I'm doing wrong now?
Thanks again for all your help!