play button being pressed by elaborate machine

‘Easy’ Is Relative

When evaluating someone else’s work I often fall into thinking “it looks so easy”; especially when the concept is simple. Yet when embarking on actually doing something that seems easy myself I’ve found that most often it’s quite a bit more difficult. Occasionally the reverse is true: what appears very challenging turns out to be a breeze.

One deceptively simple example is partially automating pausing and resuming Pandora Radio with a keystroke. While purchasing the Pandora One player/service is a quick and inexpensive solution, I was interested in automating the user-interface myself. (There are also 3rd party clients with hot-keys, but they exclude the advertisements which are how I indirectly support Pandora’s free service.)

Image Search

My first attempt was a Sikuli script to find the Pandora tab in my browser, then the play or pause button, and finally click it. As I tried reusing it on other computers I noticed higher resolutions meant Sikuli needed more time to find the tab. And if the tab was off screen, because I had too many tabs open, then it also failed. Finally the Pandora icon didn’t always appear the same on different browsers and OS’s.

Pandora’s Keyboard Shortcuts

Next I tried using AutoIt to get the Pandora window more reliably. Thankfully Pandora’s player has keyboard shortcuts, so there was no more need for image recognition. Unfortunately I found that using ‘Alt’ in the pause-play shortcut meant that browsers like Internet Explorer thought they should open the file menu. Another problem is that the key Pandora chose (space-bar) is also the default to scroll down; therefore, when the player’s frame is not active my script would only scroll the page instead of resuming or pausing playback.

Blind Mouse

To workaround the space-bar problem I resorted to blindly clicking the mouse where the play/pause button resides. Alt was still opening the file menu, so the mouse position had to carefully aligned to work whether or not the menu was visible.

Since the process was blind I retrained myself to always leave the window at the top. (One could auto-press ‘Home’ to get the browser back to the top.) Even so, the clicking was too quick for the browser to redraw at times. This required adding a small delay before clicking to get the desired result.

Off-screen Trouble

Using virtual desktops meant Pandora wasn’t always on screen. SysInternals Desktops solution was especially troublesome because each desktop was so isolated software didn’t work across them. Switching to VirtuaWin helped; though, after the script was done it left the Pandora window on the current desktop instead of putting it back where I had left it. AutoIt allowed me to minimize the window for the time being. (A better long term solution may be to keep track of the move and put it back on the original ‘desk’.) Minimizing also required it’s own delay or else the automated click may happen after the window is already off screen.

The final, ‘simple’ procedure turned out to be:

  1. Open or raise the Pandora window by title
  2. Wait a moment so the flash player can draw the button
  3. Auto move the mouse to the button’s menu-or-no-menu position
  4. Simulate the click
  5. Wait for the click event to actually play or pause
  6. Minimize the Pandora window

While this won’t work for everyone (AutoIt only works on Windows), and has a lot of room to improve, it does make my life a little easier. The process has also been a lesson in UI automation and the value of seemingly simple things.

Leave a Reply

Your email address will not be published. Required fields are marked *