Trigger chains with AppleScript

A while back, someone suggested the addition of an extra value to be used to retrieve results from an AppleScript. This is a fine idea and I’m going to take a close look at it in a future release, but the suggestion was made as a solution to a problem that could be solved by chaining triggers together using AppleScript.

Let me show you what I mean. Suppose you wanted a Hotkey that displayed track information for the current track in iTunes when pressed. You’d use a Hotkey Monitor trigger, which is simple enough. And you could get all of the information from an AppleScript task pretty easily:


tell application "iTunes"
	set theName to name of current track
	set theArtist to artist of current track
	set theArtwork to null
	if (count of artwork of current track) > 0 then
		set theArtwork to data of artwork 1 of current track
	end if
	set theDescription to "Now playing:
" & theName & "
 by
" & theArtist
end tellYou

But what to do with it? This is where the AppleScript Trigger comes in. Not only can this trigger be used to poke Proxi from iCal, Folder Actions, or anything else that can execute an AppleScript, but it can be used to have Proxi trigger itself. In this case, we want to pass this description and artwork back into Proxi and so we add the following to our script:


	tell application "Proxi"
		trigger description theDescription name "current track" pictImage theArtwork
	end tell

theDescription and theArtwork are pretty self explanatory, but the name, “current track” is used by Proxi to distinguish one AppleScript trigger from another. So next we need to add an AppleScript trigger to Proxi and set the AppleScript trigger name to “current track”. Then we can add a Screen Message task and display the Image and Description values we got from the AppleScript trigger.

You can use this technique to string together as many triggers as you need. You could even use a dialog to prompt for information and put together a bit of logic by filtering on the return value. And yes you can create a recursive trigger if you want but it doesn’t take much to overflow the stack in AppleScript.

A blueprint demonstrating the current iTunes track hotkey I described above is available here.

6 Responses to “Trigger chains with AppleScript”

  1. Frischmilch Says:

    Why didn’t Griffing think of this?
    http://proxi.griffintechnology.com/wiki/index.php/FrontRow_PowerMate_Control

  2. Kurt Says:

    This worked out great! Thank you for posting this tip. But I encourage you to make “Extra Values” available to users in AppleScript.

  3. Casey Says:

    I’d like to add an AppleScript value as well. The only potential wrinkle is that Proxi must know what type of value is being defined. So, the result of an AppleScript would have to be coerced to a text value if it wasn’t text to begin with. The AppleScript trigger allows you to send a text, number, or image value and so it will be a bit more flexible.

  4. Kurt Says:

    Casey,

    Do you have other ideas on what to use the AppleScript trigger for?

    Kurt

  5. Casey Says:

    Do you have other ideas on what to use the AppleScript trigger for?

    One possibility would be triggering from applications, such as Colloquy, which support AppleScript plugins. I’ve created a script which notifies Proxi when new messages are posted and when a user joins or leaves a particular chat room. I just knocked it together, but I can try and clean it up a bit and post it to the wiki if it would be helpful.

  6. Mortimer Says:

    I use applescript triggers to trigger Proxi from Amarok (a kde app running under X11 from Fink), to get track change events etc… It’s already on the wiki I think.

Leave a Reply