So I recently noticed that my code to combine AutoHotkey with iTunes wasn’t working, so tonight’s project was to get it working again. Luckily, AutoHotkey has dramatically developed since I wrote the last post, now bundling native COM support in a version that is generally known as AHK_L. For a full list of things added to AutoHotkey, consult the AHK_L Changelog.
So the best news here is that we don’t have to mess with low-level COM coding at all; anyone who has done so will know the pain of which I speak. Using COM is one of the most degrading, mind-wrangling and time-consuming tasks in Computer Science. Thankfully, the new syntax is simple.
Media_Next:: iTunes := ComObjCreate("iTunes.Application") iTunes.NextTrack() Return Media_Play_Pause:: iTunes := ComObjCreate("iTunes.Application") iTunes.PlayPause() Return Media_Prev:: iTunes := ComObjCreate("iTunes.Application") iTunes.PreviousTrack() Return ^Media_Mute:: iTunes := ComObjCreate("iTunes.Application") iTunes.Mute := !iTunes.Mute Return
More after the jump.
^#Up:: iTunes := ComObjCreate("iTunes.Application") iTunes.CurrentTrack.Rating += 20 Return ^#Down:: iTunes := ComObjCreate("iTunes.Application") iTunes.CurrentTrack.Rating -= 20 Return
Copy song to Dropbox
I’ve changed the function to copy a specific file location to the Dropbox, taking the COM reference out of dropbox.ahk.
Media_Stop:: iTunes := ComObjCreate("iTunes.Application") CopyFileToDropbox(iTunes.CurrentTrack.Location) Return
Other useful fields/methods
Many of the following were gleaned from this file.
- Go to iTunes Store:
- Enable visualization:
iTunes.VisualsEnabled := 1
- Toggle visualization:
iTunes.VisualsEnabled := !iTunes.VisualsEnabled
- Update iPod/iPhone:
- Path of library file:
- Seek to beginning of song:
- Fast forward:
- Play file:
iTunes.PlayFile(full file path)
- Open URL:
- If iTunes is currently playing:
- Seconds elapsed in file:
- Time (total length):
- File size (bytes):
- Play count:
- Bit rate:
- File location:
- Current playlist:
- Selected tracks:
- Name of a playlist:
- Number of tracks in a playlist:
- Length of a playlist (hh:mm:ss):
- Size of a playlist (bytes):
- Name of the first track in a playlist:
- Play first track in the current playlist:
- Number of search results for a phrase:
iTunes.LibraryPlaylist.Search("wild things", 1).Count
Hopefully this is of use to someone. If it is, I’d like you to tell me what you used it for!