Scripting iTunes: making an alarm clock

How to script iTunes have been discussed many times before. In Mac you use AppleScript, but in Windows you can instead use the Windows Scripting Host. That means you can choose either VBScript or JavaScript!

The trouble is how to exactly go about this. Even if you know these scripting languages, how do you know which commands to send to iTunes? As I always wanted a dead simple alarm clock function using iTunes and Windows Task Scheduler, I wrote a short script that I could run each morning:

  1. Open your notepad or coding environment of choice. I will choose to use VBScript instead of JavaScript, mostly because most Windows installations will association .vbs files with the Windows Scripting Host, while some might have re-associated .js-files with their preferred JavaScript-editor (ok, maybe that’s not the best reason, but it should be simple no matter the language you choose). Save your file as iTunes.vbs to get syntax highlighting, if your editor supports this.
  2. Enter the following script:

    Set objApp = CreateObject("iTunes.Application")
    Set colSources = objApp.Sources
    Set objSource = colSources.ItemByName("Library")
    Set colPlaylists = objSource.Playlists
    Set objPlaylist = colPlaylists.ItemByName("Party Shuffle")
    objPlaylist.PlayFirstTrack

    (above should be 6 rows only in your script)
    You can change “Party Shuffle” to preferred playlist, but then you would have to wake up to the same sequence of songs every morning. You could also add a:
    objApp.Shuffle = 1
    in the script to turn on shuffling, but the first song will still be the same. Party Shuffle will always pick up where you last played it.
  3. Try the script by double-clicking it from Windows Explorer or your desktop. It should start iTunes (if not already started), and start playing. If another program opens your script, you have not associated .vbs to Windows Scripting Host. Re-associate, or create a shortcut to: “wscript.exe <your path to you script in quotes>”.
  4. Now, you just have to schedule your alarm clock. Go to Windows > Accessories > System Tools > Scheduled Tasks. Start it. For simplicity, put a shortcut to it on your desktop or in your task bar. Go through the “Add Scheduled Task” wizard, and point it to your script (or wscript shortcut, if you had to do one). You can easily customize the times of the schedule, to happen only on week days, every day, every other day, etc. If you have different times every day, you can add separate schedules for the same task.
  5. After finishing the wizard, make sure you right-click on the task and go to Properties > Settings and click “Wake the computer to run this task”. The nice thing about Task Scheduler is that it can wake up your computer to for the alarm. Yes, that is right, you can hibernate or go into standby all night (do that, it will save us from some global warming) and let the computer wake up by itself. To make sure this works smoothly, also enter your Windows password under “Run As” in Properties > Task.
  6. Before trusting your alarm completely, set the task (or a new copy of the task) to run a few minutes later and hibernate the computer. Then wait until the time you set to make sure it actually manages to go all the way. Different people have different programs installed, and some might theoretically stop the Task Scheduler from running. For example: IBM-Lenovos Client Security Solution will replace the Windows authentication with its own, forcing you to manually unlock the computer before any program can run :p

That should be all. You now have your iTunes alarm clock! You can, of course, do lots of other stuff. For example – if you have a program that translates any hot key to a command, you can make scripts for going to next and previous track, play/pause and similar. To get some good ideas, check this Microsoft article out. There is also some info here and here. Finally, do you have an idea for a script that none of these articles seem to describe? Download the Apple SDK, open the zip file and then open the iTunesCOMInterface.h file. Don’t be scared by all the C code – just search through it (for example, you want to activate Repeat, search for “repeat”). The name of the methods in the C code are most of the time identical to, or similar to, the commands you need to write in your script. Good luck!

What I will miss

With only ten days left before leaving Hong Kong, it is time to start wrapping up my experience here. When I created this blog, I was supposed to reflect – dissect – living in Hong Kong, and on some few occasions I actually did so. Now, I’ll make it easy for myself and just list what I will miss. Probably, I will not fully realize these things until much later.

  • The skyscrapers, the buildings, the infrastructure, the airport, the skyline. Sweden has nothing, and I mean nothing that even compares. London seems like a village in comparison. I say it now, I can say it again – Hong Kong has the best skyline in the world.
  • Public transport. Fast, efficient, cheap, clean, the Octopus card, always on time. There are basically no possible complaints against HK’s public transportation system. I thought Sweden had a good system, but… no.
  • Shopping, especially the gadget shopping. Wanna do some shopping in the evening? Sure. 9 PM? Sure. 12 PM? Definately! Sunday, saturday, new year – doesn’t really matter. And although it can be confusing and hard to compare prices, there is a certain feeling to those shopping malls with loads of small stores, each crammed with gadgets, stuff, clothes or whatever. It is such an experience! And mostly, quite cheap.
  • Being able to go in t-shirt from April to November/December. Sure, in the spring it is very humid, but it beats Swedish, or British, weather any time. I still can’t grasp how I will survive back in Sweden, when I am already suffering here with temperatures just dropping to 15 degrees C.
  • Eating out. When a dinner costs from 20 HKD/2 Euro/20 SEK, up to 30/40, there is no point in cooking. I will have a hard time getting back to the kitchen in Sweden (either that, or coping with paying 100, at least, for a dinner). Sure, home-cooked food can taste really good, but honestly – most of the time somebody else better cook it 😉
  • The Vibe. I guess it is the same in most big cities, but seeing such alive city, going to Starbucks, shopping, seeing all cultures, business, old and new, poor and rich is the vibe, and even though Swedish cities might be alive (in the summers), they lack the range of sights, events and cultures.
  • Okay, I have to admit it. The women. My wonderful girlfriend Shirley is not an exception (and she have to excuse me for this… 😉 ), but there are plenty of very stylish/cute/beautiful girls in Hong Kong. In addition, the fashion is more colorful and exciting than typical for north European fashion. “Blond, tall and sexy”, the Swedish motto, just seems boring. Luckily, Shirley will come with me to Europe, so I won’t really have anything to miss in that department.
  • The campus. Waking up everyday with a view like this beats most things. And then I discovered, the Chinese University of Hong Kong has even better views! I have yet to see a Swedish campus that is even remotely beautiful.
  • Traveling. Hong Kong is a perfect hub for traveling, and I have still a lot to see. Like Japan. I have seen Europe before, and even though I surely will enjoy some traveling there I will wait anxiously for the day that I can go back traveling in Asia.
  • International contacts. This is essential, but nothing that is specific to Hong Kong. In an international environment you will meet people from different countries and backgrounds every day. Sure, I am not the guy that starts chatting with everyone just to know their story, but in Sweden there are, more or less, only Swedes. I will try my best to get back in the international arena, ASAP.

Of course, there are a few things I won’t miss:

  • The hazy sky. A few days, Hong Kong has wonderful sky. But most days, it is either cloudy, misty or hazy. Or all of them. It partly depends on the climate, partly on the massive pollution from China. At least I can say that Sweden can get some wonderfully blue skies, and that both in winter and summer.
  • Being away from friends, family and hobbies. Of course, this is not really Hong Kong’s fault, but going back to Sweden, the one most important thing is that I can get back to the people I used to spend time with and do the stuff I like – such as roleplaying or having family dinners. There were no real substitute in Hong Kong, although I met many good friends and had some fun sessions of gaming, it was always temporary.
  • The apartment. Sure, it was like a palace compared to student halls, but going back to Sweden, I can look forward to my own home, my own stuff, my own design. More space to store stuff, more comfortable chairs, better kitchen, etc.
  • The food culture. I have mixed feelings about this. Some Chinese food is really good, but I can probably find that food in Sweden too. However, the food I can’t find in Sweden, such as pig intestines, strange seafood, old eggs, grainy sausages, will not be missed. I have tried it, and I didn’t like it. Let’s leave it at that 😉

PS3 having problems with wireless connection

After coming back from the Asia Game Show, I fired up my PS3, and got a new reason to write something about my only problem with PS3. The Sony Playstation 3 does not just work with all routers or access points. Yes, it is semi-officially confirmed (see below):

It all began when I tried using the wireless feature of PS3 with my nimble Asus WL-530g router. The wireless connection will set up fine, even the internet connection test, but then it will disconnect after approximately 30 seconds. This will keep on happening and every time a notification message will be displayed in the upper corner of the screen – even when playing games. On top of this, the Playstation Network account will sign in and out. Surfing the web still works, if you are prepared to have to reload pages often. This problem has been noted before in forums, such as here.

Evidently, this is an unacceptable situation. I called the Sony Hong Kong support and inquired about the problem. The problem was not immediately recognized, but after my second call, I got some facts on the table. The (simplified and freely quoted) discussion went something like this:

Support: “The PS3 can have compatibility problems with different routers. We have not tested them all to function properly with PS3
Me: “How come normal computers have no problem using my router, or almost any router, for that matter?
Support: “The PS3 is not a computer. It does not work in the same way.
Me: “So, buying a new router is my only option? How can I know which router that actually works with PS3?
Support: “Most Buffalo and Linksys routers will work, but not all. We will try to post an official list of supported routers on our web site or through other channels.

I suspect that the PS3 is not a computer is a different way of saying “computers have stable wireless networking code, we do not”. Of course, technically, PS3 is quite much like a computer and in any case, if computers and handhelds have no problems dealing with any normal router, how come PS3 fails? Apparently, Sony sees the wireless ability more as a cool, extra feature than a really needed one. They still hope people just use their cables. But hey, wireless is the future and PS3 should embrace it.

Let’s see if that list of compatible routers show up. If it does, Sony indirectly admits their error. A list will in any case be a great help for anyone with these problems or any future PS3 buyers. As the support guy also said, future PS3 system updates might remove these router problems – and I believe him, I just hope it will be soon enough. Soon I will be able to test with some more routers to see if the support was right. If anyone reading this has problem with their wireless, or if their wireless works fine, why not post the brand and model number of your router for reference?

Asia Game Show

In spite of having pressing deadlines, I decided on an impulse to join Ryan for the Asia Game Show. The show, taking place at the Hong Kong Convention And Exhibition Centre in Wan Chai, was mostly a big display for Sony – it seems like they are gathering some more hype around the PS3 now than previously. There were plenty of gaming booths – approximately 30-40 PS3 booths, if not more, and lots of PSPs too. That was not, however, the main attraction. The main attraction were the many models wandering around with a crowd of photographers. Their job were, of course, to bring attention to different shops and booths at the expo, but people were too busy taking photos to buy much :) Still, I bough Restistance: Fall of man (a great PS3 FPS-game!), the movie Underworld in Blu-ray (so I have something to test on the PS3) and some gadgets. There were plenty of dirt cheap gadgets. The memory cards were especially cheap – 1 GB for 89 HKD / 9 Euro / 80 SEK.

Now, I will let the photos speak for themselves. Take a look at the complete Flickr photo set, or take a peek at some of the photos to the left.