Comments

Shake that booty for the applescript dudey

Posted by sh1mmer on Jan 2, 2007 in General

So, the Mrs and I were sitting around at home last weekend. She starts playing this game with iTunes, where she was dancing to the first minute or so of each song on one of her playlists. From rock to dance to swing and blues did she go. It was so much fun I joined in too!

In order to make this game available and easy for the rest of the world, I made a little Applescript which automates the process with iTunes.

All you need to do is save the script as an application (or download a compiled version here*), run it and shake that booty!

APPLESCRIPT:
  1. tell application "iTunes"
  2.     set playlistsList to ""
  3.     repeat with pl in playlists
  4.         set playlistsList to playlistsList & name of pl & ", "
  5.     end repeat
  6.     repeat while true
  7.         set response to display dialog "Which playlist should I use (blank for everything) ?
  8. Available playlists are:
  9. " & playlistsList default answer ""
  10.         if text returned of response is not "" then
  11.             try
  12.                 set thePlaylist to playlist named (text returned of response)
  13.                 play thePlaylist
  14.                 set the view of the front browser window to thePlaylist
  15.                 exit repeat
  16.             on error
  17.                 display dialog "Whoops! You entered a playlist name that didn't exist" buttons {"Ok"}
  18.             end try
  19.         else
  20.             play playlist "Library"
  21.             set the view of the front browser window to playlist "Library"
  22.             exit repeat
  23.         end if
  24.     end repeat
  25. end tell
  26.  
  27. property keepplaying : true
  28. repeat while keepplaying
  29.     do shell script "sleep 15"
  30.     tell application "iTunes"
  31.         if player state is stopped then
  32.             set keepplaying to false
  33.             exit repeat
  34.         else if player position> 44 then
  35.             next track
  36.         end if
  37.     end tell
  38. end repeat
  39. quit

N.B.I still haven't found a way to keep a dialog open waiting for input while doing other stuff. Anyone got any ideas?

*Does not contain a virus to the best of my knowledge, no warranty, I'm not liable if it breaks stuff, yada yada, insert usual software disclaims here.

Technorati Tags:
, , , , ,

Copyright © 2009 Kid666 Blog All rights reserved. Base theme by Laptop Geek.