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/ChristoferK Nov 26 '22
You were obviously used to working in older Mac operating systems that were in the pre-Posix days, where HFS paths were the standard, and these do necessitate specifying the drive at the start of any file path.
It sounds like you've now at least got a system capable of running Script Debugger 7, so that means it's a posix system. Posix file paths don't specify the drive explicitly, because all file paths exist under the boot disk's mount point, even files on other drives. And the boot disk will always be mounted at
"/", and your home folder is always going to be at"~/"(even if it's not in the "Users" folder).But, if you can avoid hardcoding paths, that's always going to be better, for the reasons you discovered. System Events contains a lot of constants and properties that will always evaluate to the correct location of many important folders on the system, even when their locations change. These include:
and these are just the ones in the user domain (i.e. at some level at or below your home folder). There are equivalent enumerations for folders in the system domain (e.g.
"/System","/Library", ... which are all top-level folders), and the network domain.