Monday, June 29, 2009

Invoking Spotify playlist using applescript

Spotify has plenty of Finnish children's music available so it has gained specific popularity in our household. This has rendered my older iTunes-control -scripts not that useful anymore. I decided to give Spotify scripting a go, even though I knew there's not applescript interface available. Thankfully simple key navigation is enough for the basic use case of "play random song from this playlist":

-- Invoke Spotify simply by opening a Spotify playlist or artist URL

open location "http://open.spotify.com/artist/4Zml6rzsSiVkfIIWJh6EWX"

-- Make sure we have the spotify-application on front and in focus
tell application "Spotify"
activate
end tell

-- Now navigate to the song we want to play and play it
tell application "System Events"
-- Three times tabulator = move selection to the songs list
key code 48
key code 48
key code 48
-- Wait for a while the spotify app to catch up
delay (2)
-- enter key = play selected song
key code 36
-- right key with command = next song (random assumed)
key code 124 using command down
end tell
Note that if the Spotify URL is your private playlist this still works, as the playlist is invoked locally!

Other assumptions:
  • "enable access to assistive devices" is enabled on the "Universal Access" -settings
  • Spotify URL:s properly associated to your favourite browser (tested only with firefox)
Known issues:
  • Invoking a random song requires you to set the shuffle on manually on the Spotify app
  • Naturally this generates new browser tabs on each time the script is invoked
  • As the key events are used, and even with a noticeable wait in between, this can cause really weird results if something is happening onscreen either interactively or autonomously.
  • There is no straightforward way of knowing if Spotify is already playing something. Toggling the playback off, if invoked second time (useful when used with RFID tags) isn't therefore easy.. or is there a apparent solution other than closing the app?
As this works OK, I have to print out new RFID-tag for Ti-Ti -nalle for my daughters ;)

Again, the script is not really a rocket science and most of the elements were just copy&pasted from invaluable Doug's AppleScripts. It is just fun to simply being able to control other apps in OSX!

Labels: , , ,


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/

Labels: , ,


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

Labels: , , ,


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.

Labels: , , ,


Saturday, June 14, 2008

How many channels is enough? (part two)

Continuing from my rant on the multitude of channels.

Ok, maybe the everyday reality of the communications channels is not that bad in reality thanks to the tool consolidation. Both in mobile setup and from a home/work workstation I can handle all of the necessary channels with just a few tools. The question is, does it really make it any easier?

On my primary mobile (Nokia E61i at the moment) I use Fring to handle MSN, GTalk and Skype. Via XMPP it can also deliver the updates from Jaiku (or twitter, if needed) back and forth. The only missing piece is IRC for which I need to launch a separate application (putty or Mirggi). For my email on the go I use gmail, through mobile website or with the java app. The email funnels all the reminders from the social networking sites I need really to react to.

On the workstations browser is the key. At home I use OSX applications like Adium or Skype for best user experience but at work or from on the road Meebo has it all. Again, for IRC I need to ssh to my unix account. Email, Jaiku and the social sites are all handled through the browser.

Funneling everything through the browser also helps to the challenge of using one computer at the home for all the family members. Using many user accounts at the iMac does not really work for us, things need to be handled in "one session". There would be a room for development of an "identity swithch" which would authorize all the native clients with correct credentials - I wonder if anybody has been experimenting with this using e.g. OSX keyring?

With me using everything through the browser and my wife using the native clients and her own email account with separate login we can manage somehow.

With all the social sites, blogging systems, and IM networks having their more or less public and open API:s there is still room for more consolidation. Supercharging applications like Adium or Mobile goodies like Fring to handle all the listed channels could be possible, but will the projects like that take the controversial task to get "all in". Before that, only way for the end user is to be selective with the networks and bear with the fact of not reaching everybody you want - or maximize the reach and bear with the time consumption and brain bandwith overhead ;)

Labels: , , , , ,


Sunday, September 30, 2007

One way to get your TV shows to your S60 mobile for viewing

I commute daily via either bus or train & underground. The one-way trip is 40+ minutes door to door. Sometimes I read or listen to podcasts or audio books. Once in a while I watch a TV show from my mobile or Nokia 770 tablet.

I have moved just lately to following tool chain to get the shows to my mobile is eyetv, iTunes, MyTunesRSS and S60 podcasting. It is not by all means perfect but it is definitely usable.

1) Recording the TV shows
On my iMac I am using Miglia TVMini for watching and recording . I bought the stick when the Elgato eyetv (http://www.elgato.com/) was still bundled with it. I just love the eyetv software. I haven't seen a match of the similar software in the Windows world.

So, I record the TV-shows as usual from the terrestial DVB. We use the iMac as primary TV at home as the pvr functionality is just so convenient. This might change when we buy a proper set-top-box to the living room - this move would free the mac for use as a computer ;)

2) Converting the files suitable to format suitable for the S60 phone

In this easy-as-possible route, I use eyetvs built in "convert to iPod" functionality. To make it happen automatically I tick the "convert to iPod" checkbox for the scheduled shows I want to view from the mobile. I found that though the "Fastest MP4" option produces files which are viewable on the phone. The E61i cannot handle the H.264 which would produce much smaller files. There is an interactive way to export files from eyetv with more suitable parameters but you cannot make that automatic.

eyetv_export_choises.png
Default (iPod) export options of eyetv

I have not yet checked whether the default option that uses H.264 codec produces files that are viewable in N-series models. The E61i does not have the codec nor the horsepower to do view them.

3) Making the files available

In this stage I used to transfer the files via USB cable which is reasonably fast but requires manual steps and time with the computer: Not usually doable in a busy morning with a little girl living in the house. I wanted to have the phone update the shows wirelessly in automatic fashion during the night.

As I use the S60 podcasting application daily I thought to give it a try also with the videos. E61i has WLAN and is therefore able to contact our home network. The missing link was a server software to produce RSS feeds with the video files as enclosures.

MyTunesRSS
MyTunesRSS generated page

After some googling MyTunesRSS (http://www.codewave.de/products/mytunesrss/) seemed suitable for the job. The ease of installation was also reason to try it first. The software is intended for interactive browsing and streaming for your iTunes library, especially PSP in mind. PSP browser seems to support RSS nicely to make it work. When trying out the software and browsing the generated pages, I found out that the generated RSS link is static per iTunes folder, and can be therefore reused. As the generated pages require login and password, having the RSS feed to change its address would render the software unusable for me. The link is very long so copy&pasting and e-mailing was only practical way to get it to the phone.

4) Getting the files to the phone

The S60 podcasting application (http://www.nokia.com/podcasting) was able to use the RSS feed without problems. Setting the app to use the home WLAN and updating the feeds resulted the shows and their sizes to show on the screen exactly the same way as audio podcasts.

TV programs from iTunes
S60 podcasting view to the served videos

Downloading the shows is slow business. I haven't investigated this further whether it is due to the S60 application, MyTunesRSS, WLAN encryption or the WLAN throughput in the phone in general. The download speeds are around 70-80kb/s, which adds up to really long download times - over an hour per 500M episode.

Despite long download times I prefer this approach over the USB cable. If I just remember initiate the downlaods in the evening the mobile is "topped up" in the morning.

5) Things to improve

- Make the files smaller than the eyetv default (e.g. using applescript and external utilities)
- Better alternative to MyTunesRSS (easier RSS feed link(s))
- Enhance the transfer speed
- The S60 podcasting application has some bugs & annoyances.
- Get a bit more suitable phone, e.g. N95 8GB, which is faster and could handle also the H.264.

Update 20071005: Tried the system with N95. The WLAN download rates were considerably better being between 300-600kB/s. With those speeds rather quick covert+download cycles could be possible.

Labels: , , , , , ,