Keystroke launch of script for free, for OS 9.2.2

I am a little stumped by this one:
I have OS 9.2.2. I have iTunes. I have headphones. I have music. I want to be able to pause/play iTunes with 1 key. I don’t want to pay for that feature. I don’t want it to take very long to send the appropriate command to iTunes.

So, I tried this: I wrote a script that get the play status of iTunes. If iTunes is playing, then pause it. If iTunes is doing anything else, play. It works fantastic, and it is nearly instantaneous when it runs from Script Editor.

Now, I want to do this with a keystroke from anywhere in the OS. I have the Hot Function Key control panel. I use it to launch the script saved as an application. It takes too long to load the application compared to grabbing my mouse,and using the control strip module for iTunes. So I thought I could save it to stay open after launch. That way, after it loads the first time, I can keep activating it and get my nice near-istantaneous control. But, little did I realize that the “on run” just works on launch. Or perhaps I am missing something.

Here is what I have now:

on run
end run
on beCool()
tell application "iTunes"
set whatChaDoin to player state--what is iTunes doing?
if whatChaDoin = playing then
end if
end tell--app "iTunes"
end beCool

It aint cool. What can I do? I know there is “T-Minus Ten” but I don’t want to pay for that one feature, and it is not as fast as running the script from Script Editor. I’d settle for understanding how to keep a script app open and just get it to run every time it’s activated, or ideally, I’d like a compiled script to run á la OSA Menu (which I know has keyboard shortcuts–it just is wonky with CarbonLib apps like Freehand 10, Quicken Deluxe 2002, Script Editor etc.)

BTW, I’m using a beige G3 with ADB keybaord. I think there are some keys on newer USB keyboards that do that type of thing, but I haven’t had my hands on a new desktop machine in two years. (I do have a dual USB iBook, wich has a mute key that I like to use for essentially this purpose.)
Thanks Everybody! Have a great weekend!
Ian Goos
PS, how does one get a script listing in this BBS without manually formatting it? I couldn’t find the faq quickly for the BBS.

If what you do when the app is already running in any way simulates a dbl-click on the icon in the Finder then this should work:

on reopen
end reopen

Fantastic! Way Cool!. Works just like it should! And it’s fast just like I wanted.

Now I have to put in a way to drop me back to the App I was in when I “reopened” that script app. (Keyboard shortcuts uses the Finder as the launcher of any keybaord shortcut–leaving me in the script I ran instead of the program I was in when I first ran it.) But I believe that an idle handler to check the current process may be the best bet. Any suggestions?

Thanks for your help

A lot of the time a simple ‘tell app whatever’ will be enough but the Finder is full of surprises and you need to be prepared to have alternatives up your sleeve. There are many ways of doing what you want, especially if you use various 'osax’en, but for starters you may find it useful to play around with this:

set chosenApp to (choose file of type "APPL" with prompt ¬
	"Chosse an app to experiment with") as string
tell application "Finder" to set appName to file chosenApp's name

tell application chosenApp -- Path  needed first time
	say my getWhere()
	-- do the biz
end tell

tell me
	say getWhere()
end tell

-- Then use ONE of these two
tell application appName to activate -- Now it's running the name is enough
--tell application "Finder" to set process appName's frontmost to true
-- the latter is needed where, for instance, the app has no AS dictionary ('AETE' resource)
say getWhere()

to getWhere()
	tell application "Finder" to return ¬
		"I'm in " & (processes whose frontmost is true)'s name
end getWhere