Saturday, March 07, 2009

Simple applescript for playing music in iTunes

In addition to make skype video calls I thought it would be nice to give my kids some control over playing music on the iMac. So, a new rfid tag was assigned to following simple applescript:

tell application "iTunes"
if player state is playing then
stop
else
set the view of the front browser window to playlist "kertun musaa"
set myNumberOfTracks to number of tracks in playlist "kertun musaa"
set randomTrack to (random number (myNumberOfTracks - 1)) + 1
play track randomTrack of user playlist "kertun musaa"
end if
end tell

So when the tag is shown to the reader the script either
  • stops the playback if itunes is playing a something, or
  • if nothing is playing, starts a play a random song in a named playlist
The script would've been even more simple if iTunes would allow setting the current playlist. Then I could've used the native shuffle mode of the player.

Using applescript one can do almost anything on iTunes. A good source for further information is http://dougscripts.com/itunes/

Friday, March 06, 2009

RFID "calling cards" for OSX and Skype

I made a simple "calling cards" for my daughter(s) which enable her to make a Skype video call to me and to her grandparents without using keyboard and mouse. In order to make the call she would just show the card with right image to the reader. Computer would respond by saying aloud either "calling grandma" or "cannot make the call to grandma", depending whether the other party is online or not.

cheap rfid-reader and "calling cards"

Setup:
  • iMac with Skype installed
  • Tikitag/Touchatag rfid reader. Bought the reader and some tags for about 12€ (75% discount) when the company changed its name.
  • Applescripts for calling to grandmas and myself at work, saved as application. The scripts check if the target is online, gives voice feedback using speech synthesizer, and makes the call with the window maximized.
  • Rfid tags assigned with local URL:s at touchatag service. The local url is simply a link to the application to start when the tag is shown to the reader. As example, an URL to "call my work skype app" is
    file:///Applications/as/call_simo.app
  • Pictures in see-through plastic pouches. The Rfid tag is put behind the image. One could also e.g. laminate the cards.
I have also experimented having Nokia N770 internet tablet next to the reader showing visually who is online and who isn't. Having the extra device on the table did make the setup look a bit complex. Let's see with the target audience if is it needed or not. ;-)

Controlling a computer via non-traditional methods feels nice. If the setup works reliably and the actual interaction makes sense I will definitely expand the use to playback of some favourite music etc.

OK, nice hack but will it be used for real? We see it next week when the family comes back home ;)

EDIT: Added the example of a local URL

Thursday, March 05, 2009

Learning applescript: controlling skype

While I've always known that you can control many of the applications running in OSX using applescript I have very rarely tried that myself.

Now, as I have a use case of semi-automation of skype video calling for the kids I started experimenting. I did buy a tikitag rfid reader on cheap which will be used for triggering the call.

Here's what will be triggered by the rfid tag. This simple script checks if person xxxxxx is online and tries to open a call if he is. At the same time the script enlarges the call window to full screen for maximum video size. I have added some text-to speech notifications just for sake of experimenting, most probably I will replace them later with recorded samples.

Edit: Updated the script a bit and framed it in

SkypeCall("xxxxxx")

on SkypeCall(login)
set AppleScript's text item delimiters to " "
tell application "Skype"
set foo to send command "GET USER " & login & " ONLINESTATUS" script name "MyScript"
set UserStatus to my GetPart(foo, 4, " ")
if UserStatus is "ONLINE" then
say "soitan"
send command "CALL " & login script name "MyScript"
copy (run script "tell application \"Finder\" to desktop's window's bounds") to bounds of window 1
else
say "[a] onnnnissstu!"
end if
end tell
end SkypeCall

on GetPart(s, p, d)
set theList to every text item of s
return (item p of theList)
end GetPart
I used this macoshints article as an example.