Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent an AppleScript script from changing its own modification date when using passed arguments
    primarykey
    data
    text
    <p>I have an AppleScript script that I use to display iTunes track information on my desktop with GeekTool. I use <code>on runargv</code> to pass different parameters to the script so I can show different parts of the track information without duplicating the script (for example, I can get just the title by running <code>osascript itunes.scpt title</code> and I can get the artist/album by running <code>osascript itunes.scpt album</code>). </p> <p>However, every time I run the script with an argument, the actual file modification date is changed—it seems that the script is writing <em>something</em> to itself or making some sort of modification. </p> <p>This isn't ordinarily a problem, except in OS X 10.7, where Lion introduced file locking for files that haven't been modified in more than 2 weeks. Once my iTunes script is locked by the OS, it can't make any more of these invisible self updates when it runs, and my system log gets riddled with errors like this:</p> <pre><code>osascript: couldn't save changes to script /path/to/script: error -54 </code></pre> <p>I can fix this temporarily by making some modification to the script manually (adding empty lines, for example), but two weeks later it all breaks down again because Lion locks it. </p> <p>I could theoretically disable file locking systemwide to fix this, but I'd rather not—I like it for other things. </p> <p>So, how can you use <code>on run argv</code> to pass arguments to AppleScript files <em>without</em> changing the modification date of that script?</p> <p>Here's a minimal working example. If you run this from the command line (<code>oscascript test.scpt blah</code>), the script's modification date will change.</p> <pre><code>--test.scpt on run argv tell application "iTunes" if player state is playing then set trck to current track set title_text to (get name of trck) return title_text &amp; " " &amp; item 1 of argv end if end tell end run </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload