How are my Apple Scripts saved on Google Drive being corrupted?

63 Views Asked by At

Note, I'm not asking what I should do, or how to fix this problem, or why saving AppleScripts in Google Drive is a bad idea - I already know that and have a solution to my problem. I understand it enough to fix it, but I just want to understand, at a deeper level, what happens when you DO save an AppleScript in google drive. I'm just really curious about what happens and would like to understand the issue better for my own edification. I have a couple questions, but let me first describe the behavior I see...

I have a Scripts folder in my google drive, in which I have saved AppleScripts (among other scripts) for years without much issue. Every once in awhile (maybe 3 times a year), one of those scripts would randomly stop working, and instead of looking into it, I just grabbed a copy of the script from elsewhere and just replaced it (kicking the can down the road).

Today, it happened again to an AppleScript named complete_reminder.scpt and I didn't have a copy handy, so I looked a bit deeper. I eventually restored a copy from google drive's file history, and moved it out of google drive. Google had a bunch of versions and it appeared that there may have been a version for every time I ran it, and based on what I read when I first attempted to try and fix the script manually, I believe (though I don't know) that the versions were due to the fact that the osascript command that I was using to run it from node-red was compiling and saving it each time.

When I eventually discovered that code in the script had been altered, I created text copies of the .scpt versions and did a diff between it and the restored version:

diff complete_reminder_restored.osa complete_reminder_googles_mangled_version.txt
30c30
<   set remWasRunning to (application "Reminders" is running)
---
>   set remWasRunning to (application "osascript" is running)
37c37
<       tell application "Reminders" to quit
---
>       tell application "osascript" to quit
84c84
<               tell application "Reminders"
---
>               tell application "osascript"
86c86
<                       set completed of every reminder whose completed is false and name is myTitle to true
---
>                       set «class comb» of every «class remi» whose «class comb» is false and name is myTitle to true
88c88
<                       set completed of every reminder in list myList whose completed is false and name is myTitle to true
---
>                       set «class comb» of every «class remi» in list myList whose «class comb» is false and name is myTitle to true
107c107
<           tell application "Reminders"
---
>           tell application "osascript"
109c109
<                   set rems to (every reminder whose id is remid)
---
>                   set rems to (every «class remi» whose id is remid)
112c112
<                       set completed of rem to true
---
>                       set «class comb» of rem to true
124c124
<               tell application "Reminders"
---
>               tell application "osascript"
127c127
<                       set rems to (every reminder whose id is remid)
---
>                       set rems to (every «class remi» whose id is remid)
130c130
<                           set completed of rem to true
---
>                           set «class comb» of rem to true

For some reason, the hard-coded static string value "Reminders" had been changed to "osascript" and all of the reminders-related dictionary terms were changed to things like "«class remi»".

I run this particular script almost daily, and it worked for years without issue. Today it started failing because every time it ran, it asked me where the application "osascript" was, and since I wasn't at my computer to respond, it would just time out and my node-red flow would send me the error Can’t get application "osascript".

I think that the changes to the variables are being made by the compilation. So my questions are:

  1. Is the (osascript) compilation what is changing my code (as written)?
  2. What could be happening to cause the compilation to do that?
  3. Why is it replacing "Reminders" with "osascript"?
  4. Why is this occurring so rarely?
0

There are 0 best solutions below