Hack19.Control iTunes from Phlink


Hack 19. Control iTunes from Phlink

If you have a ton of iTunes tracks just sitting there on your hard drive, why not put them to work in Phlink.

One of the coolest things about Phlink is its AppleScript abilities. Much like PhoneValet and other desktop telephony packages, custom scripting is where all the fun lies. Sure, letting folks record their voicemail onto your computer is fun, but integrating the other stuff on your computer with the phonethat's even better. You've seen how to do some basic database interaction between Phlink and the Address Book [Hack #18]. That's a great starting point for this hack, because it introduces the events that can trigger scripts within Phlink. If you haven't been there already, check it out, come back, and I'll be waiting here with this iTunes hack.

Your iTunes music library makes the perfect source for on-hold music, or just for a cool telephone gimmick like a "remote phone jukebox." The following AppleScript will actually search through your iTunes music library and find non-copy-protected songs (i.e., songs imported from CDs or MP3 files, and not purchased online) to play for the caller:

 on do_action given call:my_call tell application "iTunes" set track_found to false set num_retries to 0 repeat until track_found set my_track to some file track of library playlist 1 if (kind of my_track contains "Protected") is false then  set track_found to true else set num_retries to (num_retries + 1) if num_retries > 100 then exit repeat end if end if end repeat set my_song_file to the location of my_track end tell tell application "Ovolab Phlink" tell the_call to play (my_song_file as alias) end tell  end do_action 

my_song_file is a variable that stores the location of a song to play for the caller, which is triggered to play in the fourth-from-last line in the script. You can trigger this bit of AppleScript from any of Phlink's event-handling scripts (ring, greeting, hangup, etc.). The Ovolab Phlink user manual, written by fellow O'Reilly author Matt Neuberg, provides a scholarly introduction to all of Phlink's event-handling scripts.

2.13.1. Automatically Pause iTunes, Resume iTunes

Ovolab provides the following script to pause iTunes music playback when the phone rings. (This script is really cool. As Forrest Gump would say, that's about all I have to say about that.) Save it as ring.scpt (or modify your existing ring) and put it in the Phlink Items directory:

 on incoming_call given call:the_call set my_paused to false tell application "Finder" if (exists of (every application process whose creator type \ is "hook")) is true then tell application "iTunes" if player state is playing then set my_paused to true pause else set my_paused to false end if end tell end if end tell tell application "Ovolab Phlink" tell the_call make new bag with properties \ {name:"pauseitunes", waspaused:my_paused} end tell  end tell    return false    end incoming_call 

Now, to resume iTunes automatically when the phone call is hung up, add this to your hangup script:

 on do_action given call:the_call tell application "Ovolab Phlink" tell the_call try if waspaused of bag "pauseitunes" is true then tell application "Finder" if (exists of (every application process whose \ creator type is "hook")) is true then tell application "iTunes" to play end if end tell end if end try end tell end tell end do_action 

For more fantastic Phlink scripting magic, be sure to visit the message board at http://www.ovolab.com/, and for some more cool ideas for iTunes/Phlink scripting, visit the source of several of these scripts, http://www.gunsmoke.com/scot/home_automation/phlink.html.




VoIP Hacks
VoIP Hacks: Tips & Tools for Internet Telephony
ISBN: 0596101333
EAN: 2147483647
Year: 2005
Pages: 156

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net