|
|
A shell/AppleScript interaction trick
Thanks, gshenaut and others, for the "exec" workaround in its many shapes and forms suggested in this thread. I found this thread as an AppleScript newbie trying to create shebang-enabled AppleScripts, only to find out it don't work (much to my surprise, I must say!!!) Although the "exec" workaround definitely has it uses, it's not exactly a replacement for "the real thing", though: if '#' was recognised as a token for single-line comments in AppleScript, then the above could be written as:
The nice thing about this script is that it would be valid AppleScript, meaning you would still be able to edit, run and debug this script in the "Script Editor", because the shebang line would be parsed as a single-line comment, but at the same time it would be an executable shell script. You basically get the best of both worlds: it's a proper AppleScript, which you can run, compile, install etc like any old AppleScript, but at the same time it is a self-contained, executable shell script, that can be integrated with other scripts - possibly in other scripting languages like sh, perl, ruby etc - and that can also be integrated with other Unix facilities - such as cron for instance. Compare this to the "exec" way of doing things (applies to all of the above suggested variants):
... which is not exactly the same: this is indeed an executable shell script, but it is no longer a proper AppleScript, meaning you loose all the benefits mentioned above. As mentioned earlier, I'm new to AppleScript, so maybe I'm missing something here, but I would have thought it to be very easy to make AppleScript treat '#' as it treats '--' ie. as a token to identify single-line comments?!? Have the AppleScript developers at Apple dropped the ball on this one?!? I would think that as a natural consequence of creating the "/usr/bin/osascript" utility, you'd ensure proper shebang support in the interpreter? Anyone from Apple lurking here who would be able to enter this as a feature request for the next version of AppleScript??? :-) |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|