Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comprehensive Applescript Reference Book (Re: Applescript equivalent of $0 in shell script)




On Oct 15, 2006, at 2:55 PM, Philip Aker wrote:
I'm not entirely clear on what you want to accomplish, but you can script application bundles easily with regular scripts:


I should have stated my intention first. That's code sharing.
I wrote an Applescript to convert music file format in iTunes.
There are many options for conversion and currently the script asks every option
in the 'display dialog'. Some of these options are of frequent use and I want to do them by one click.
My envisioned solution to implement this mechanism is to make symbolic links to the script and call them
in the 'iTunes Script Menu'. For this to work, I need '$0'-equivalent in Applescript. Namely, the script
is to obtain the name of file off which it is launched and changes what it does according to the file name.
For example, let the name of the script be 'Convert.scpt' and let us make symbolic links to it named 'AAC.scpt',
'DeEmph.scpt', and 'Add2iPod.scpt'. Put all of them in the directory ~/Library/iTunes/Scripts so that
their file names appear in the 'iTunes Script Menu'. The script asks many options if it is launched as 'Convert'
but it only de-emphasize the selected tracks if it is launched as 'DeEmph", etc.


The script must be saved as 'Script' since some of the functions in the script are called by the command 'osasubr',
which can execute a function in an Applescript file from a shell script. This is necessary because 'Convert.scpt'
offers 'batch option', which allows me to do batch conversion later.


Application bundles and Script bundles are not displayed in the 'iTunes Script Menu'.
An application bundle named 'ZZPath2Me' that contains the code


set myPathM to (path to me)
display dialog (myPathM as string)

can display its file name when it is called by a script named 'ZZTestPath' that contains

tell application "ZZPath2Me" to run

I made a symbolic link 'ZZSymLink2Me' to 'ZZPath2Me' and made a script

tell application "ZZSymLink2Me" to run

When I tried to save the script, "ZZSymLink2Me" was changed to "ZZPath2Me"
and it is clear that my plan is invalid.



There are other scripting facilities too. Tcl scripting language <x-man-page://tclsh> has AppleScript support (maybe some others like Python and Perl too).

I didn't know that. I've been heavily depending on Expect/Tcl since NEXTSTEP days.
Expect/Tcl is the script of my choice.


My OSA components TclOSA, PerlOSA, PythonOSA, RubyOSA, ShOSA might be of some help, and I believe appscript for Python by Hamish Sanderson has some iTunes scripting examples. 


They shall be of great help to me. Thanks.


The requirements for 'path to me' in the above script are OS X 10.4 minimum, saved as a script bundle, and that it be run from a suitable executable.
There is no problem saving the above script in OS X 10.4.8. But you can not run it in Script Editor.


You can put it in ~/Library/Scripts and run it from the Script menu in the menu bar.

You can run it in Terminal by:

  % osascript ptm.scptd

I don't know much about iTunes but you can always run a script which calls 'osascript' to call your script.

Philip Aker email@hidden



---
H.T.
Any mail that does not come from this mailing list is ignored.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden
References: 
 >Comprehensive Applescript Reference Book (Re: Applescript equivalent of $0 in shell script) (From: "Hiroshi T." <email@hidden>)
 >Re: Comprehensive Applescript Reference Book (Re: Applescript equivalent of $0 in shell script) (From: Philip Aker <email@hidden>)
 >Re: Comprehensive Applescript Reference Book (Re: Applescript equivalent of $0 in shell script) (From: "Hiroshi T." <email@hidden>)
 >Re: Comprehensive Applescript Reference Book (Re: Applescript equivalent of $0 in shell script) (From: Philip Aker <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.