I have an AppleScript script that I use to display iTunes track information on my desktop using GeekTool. I use on runargv to pass various parameters to the script, so I can show different parts of the track information without duplicating the script (for example, I can only get the title by running osascript itunes.scpt title , and I can get the artist / album by running osascript itunes.scpt album ).
However, every time I run the script with an argument, the actual date the file was changed changes — it seems like the script is writing something to itself or doing some kind of modification.
This is usually not a problem, with the exception of OS X 10.7, where Lion introduced file locking for files that have not been modified in more than 2 weeks. When my iTunes script is locked by the OS, it will not be able to do more of these invisible self-services when it starts, and my system log is riddled with such errors:
osascript: couldn't save changes to script /path/to/script: error -54
I can fix this temporarily by making some changes to the script manually (for example, adding blank lines), but after two weeks it all breaks down again because Lion blocks it.
I could theoretically disable file locking all over the country to fix this, but I would prefer - I like it for other things.
So, how can you use on run argv to pass arguments to AppleScript files without changing the date that this script changed?
Here is a minimal working example. If you run this from the command line ( oscascript test.scpt blah ), the date the script was changed will change.
--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 & " " & item 1 of argv end if end tell end run