VLC - AutoPlay Music CD

Wednesday, October 26, 2011


VLC - AutoPlay Music CD - iMac OSX Applescript

I do not use iTunes, nor do I have any desire to do so.  I do, however, enjoy using VideoLAN's VLC Media Player, but with my current OSX 10.6.8 operating system, my VLC Media Player doesn't have the option upon instillation to make it the default media player.  I have no idea why.All I know is that whenever I insert a Music CD into my drive VLC will not play the disc.

It may be different for you, I don't know.  But, if I open my System Preferences > Hardware > CDs & DVDs > "When you insert a music CD:" and change this option from "Open QuickTime Player.app" to "VLC.app", it will not play.  I must choose the option to "Ignore" then manually open VLC and choose to Open Disc.  Even then it will not play properly as it will try to play the CD at the exact same time as trying to populate the VLC Playlist with the contents of the CD, therefore the music stammers and stalls at the two operations fight over control of the disc drive.

What solved this was to open the Audio CD disc folder, select all of the audio files, and drag them to the VLC PlayList, and play them from there (drag-dropping them to the player interface would also cause a fight over the drive by as described above).  This works, but the tracks are out of order 1, 10, 11, 12, 2, 3 ... 9. Very annoying to someone who likes to listen to an album in order.


So, here's the solution.  Open your AppleScript Editor (system app) and paste this into the window:


on music CD appeared d
   
    tell application "VLC"
        OpenURL "/Volumes/Audio CD"
        play
        delay 1
        stop
        set numberOfFiles to count of "/Volumes/Audio CD"
        delay (numberOfFiles * 1)
        play
    end tell
   
end music CD appeared

Save the file as a Script file, suggested name "VLC Autoplay CD.scpt", put it somewhere on your computer.  Maybe in HD > Library > Scripts or MyComputer > Library > Scripts.  Now, simply go to your "When you insert a music CD:" preference and choose "Run Script" and select your "VLC Autoplay CD.scpt" file.  That's it.  The next time you insert an Audio Music CD, it should play automatically with VLC.

The above script assumes that you are using an iMac desktop computer, you have VLC Media Player already installed, and that your Audio CD drive  is indeed located at the "file:///Volumes/Audio CD" directory or "/Volumes/Audio CD".  If you are using a laptop or an external drive etc. it may be in a different location.  I'm sure there's a way to have that drive path automatically detected by the script, but I haven't the time nor the motive to figure it out as the above is simple works for me and is easy for others to edit for their own needs.

If you have any useful changes or additions to this script, let me know, make a comment.

Update:  hm, seems that this only works if the playlist is clear to start with.  If there are other items in the playlist, it will start playing the last item to be played, such as a movie you watched before trying to listen to this music CD.  So, I updated the scripts like this to quit VLC (which clears the playlist) then restart it:

on music CD appeared d
   
    tell application "VLC"
        quit
        delay 2
        OpenURL "/Volumes/Audio CD"
        play
        delay 1
        stop
        set numberOfFiles to count of "/Volumes/Audio CD"
        delay (numberOfFiles * 1)
        play
    end tell
   
end music CD appeared

1 comment:

RawMuse said...

Very useful, thanks Scott!

previous home next
COPYRIGHT © SCOCASSO