Saturday, March 6, 2010

Control lala website from powershell

I recently discovered the lala web music service. I like the idea of having a music collection in the cloud, but I also like having shortcut keys to play/pause, skip, etc, while I'm in another app. PowerShell can control Internet Explorer, so I can do this by calling the following script from AutoHotKey (or the like):

# usage: lala.ps1 -PlayPause -Status
param([switch]$PlayPause, [switch]$Previous, [switch]$Next, [switch]$Show, [switch]$Hide, [switch]$Status)
$app = New-Object -ComObject shell.application
$ie = $app.Windows() | ?{ $_.LocationURL -match "www.lala.com" }
$doc = $ie.Document

if ($Show) { $ie.Visible = $true }
if ($Hide) { $ie.Visible = $false }

if ($Previous) { $doc.getElementById("headerPrevButton").Click() }
if ($PlayPause) { $doc.getElementById("headerPauseButton").Click() }
if ($Next) { $doc.getElementById("headerNextButton").Click() }

if ($Status) {
$doc.getElementById("headerTrackTitle").InnerText
$doc.getElementById("headerTrackArtist").InnerText
}


This version expects a lala window to already exist and have music queued up. Future versions will handle this more robustly.

No comments: