Skip to content

Instantly share code, notes, and snippets.

@battis
Last active April 23, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/ea43e0eea00e478e2298f2828f903ea6 to your computer and use it in GitHub Desktop.
Save battis/ea43e0eea00e478e2298f2828f903ea6 to your computer and use it in GitHub Desktop.
Exploit iOS autoplay-on-connect bug for greater joy
property prefix : "A A "
property current : "Current First Play Track"
property next : "Next First Play Track"
on run
demoteCurrentTrack()
promoteNextTrack()
end run
on demoteCurrentTrack()
tell application "iTunes"
repeat with t in every track of playlist named current
if name of t starts with prefix then
set name of t to ((characters ((length of prefix) + 1) thru -1 of (name of t as string)) as string)
end if
end repeat
end tell
end demoteCurrentTrack
on promoteNextTrack()
tell application "iTunes"
repeat with t in every track of playlist named next
set name of t to (prefix & name of t)
end repeat
end tell
refreshPlaylist(next)
end promoteNextTrack
on refreshPlaylist(playlistName)
tell application "iTunes"
delete tracks in playlist named playlistName
end tell
end refreshPlaylist
@battis
Copy link
Author

battis commented Apr 23, 2019

I found myself vexed by the way iOS arbitrarily chooses to play a song whenever I connect my phone to my car. Vexed because it's a dumb thing to do, and vexed because I had no control over which song got played, because it was always just the first one alphabetically.

But wait... that means that I do have control!

I created three playlists in my iTunes library. First, a playlist of songs that I might want to hear as I plugged my phone into my car:

First Play Pool playlist

Then a playlist that randomly selects one of those songs:

Next First Play Track playlist

And then a playlist that shows all of my songs from that pool that have been tricked out to be alphabetically first in my library:

Current First Play Track playlist

And then I wrote a little script that renames songs to move them between those playlists and (for completeness), scheduled cron to call that script every night:

0 2 * * * osascript "/path/to/Rename Track for First Play.scpt"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment