Corrupted AppleScript

I have an AppleScript that KM runs at periodic intervals. This morning, after updating to MacOS 26.5, KM started giving me errors that the script file wouldn’t run. I tried to open it in Script Editor, but it says, “The document could not be opened.” (with the name of the script replaced with )

The file in the Finder shows at 74 KB, but in the terminal it shows zero bytes.

Even stranger, I have a bunch of Time Machine backups of the file, but they all show up the same in Finder/Terminal, and none of them open either. Other AppleScripts in the same folder open just fine. This is the only file in that folder that shows zero bytes.

The script worked fine yesterday.

This is also the only one that KM runs automatically at intervals. Is there any chance that KM damaged the script somehow?

Don’t know. But if you say it worked yesterday, one of your TM backups from before yesterday should be valid. If not something else is causing this.

Please check if you have not run out of disk space. That can lead to these type of behaviors as well.

I’m definitely not out of disk space, 300 GB free on a 1 TB SSD.

But I got it fixed. Script Debugger was able to open the file, and I copy/pasted the source back into a new Script Editor window.

This script was originally created in 2001, so AI thinks that it was saved as an old format that MacOS 26.5 no longer supports. So this solution may be helpful for some other old-timers like me.

2 Likes

Glad it works. It remains strange that you saw a zero bytes file in the terminal. That was what I was focussing on. Anyway, it works that is most important.

Files with the .applescript extension are source text, and don't encounter this problem.

Files with the .scpt extension are, however, compiled into an intermediate byte-code, which does not always match the requirements of a newer version of macOS.

Always keep a source code version from which you can Save As to a .scpt copy – recompiling to a version that will work on a new iteration of macOS.

2 Likes

osadecompile was an interesting tool for this too. It didn’t work for the old version, but it works great for rendering other .scpt files to text.

2 Likes

Thanks @ComplexPoint for flagging that.

I just found a discussion that touches upon the technological issues that shaped Apple’s choice of format for .scpt files: Why are Script Editor .scpt files not saved as plain text files?

The discussion also links to a paper on the history of AppleScript by William R. Cook (no relation, I presume) and just a tiny bit more about the osadecompile shell command that @acekm highlighted.

It's the same Bill Cook who co-created (with Warren Harris, also a co-author on that paper) AppleScript while at Apple, if that's what you mean.

No, I had gathered that much. :grinning_face_with_smiling_eyes: I was alluding to Tim Apple (vaguely, I must admit).

1 Like