auto-create symlink to currently inserted DVD

3

Is it possible to use applescript or a shell script to automatically create a reference to the currently inserted DVD? If I pop out Midsomer Murders DVD and insert Star Trek, the Wrath of Khan, the path changes from, for example /Volumes/MM_SET_17_DISC_1 to /Volumes/ST2_DISC1

Finder supports launching an applescript when a disc is inserted, so I want to auto symlink the volume name to something like /Volumes/DVDFOLDER

Thanks!

alphablender

Posted 2012-07-14T21:10:03.573

Reputation: 133

Answers

0

As you have noticed, the volume name displayed by OS X changes with every DVD you insert, which makes symlinking to it moot. However, at the lower level of BSD devices, the DVD drive has a handle independent of volume names – its filename in the /dev pseudo-filesystem, where you will find all your drives as /dev/disk# (for the root disk level) and /dev/disk#s# (for the disk partition level) – “#” being a digit.

OS X provides the diskutil utility to handle drives via the their device filenames. Insert a DVD and do

diskutil list

to find out which device filename your DVD drive has (for the sake of this example, let’s say it’s disk3). Once you know that,

diskutil info disk3

will show you all information about the disk – notably its Volume Name and, better even, its full Mount Point path, which you can extract with a regex and pipe into ln:

ln -fhs "$(diskutil info disk3 | sed -Ene 's#[[:space:]]*Mount Point:[[:space:]]+(/Volumes/.+)#\1#p)" /path/to/DVD

will get you a symlink to the DVD volume called “DVD” in /path/to. You can wrap that into an AppleScript or maybe AppleScript or Automator application and set it to run whenever a new video DVD is inserted (note this will leave you with an invalid symlink when you eject the disc).

kopischke

Posted 2012-07-14T21:10:03.573

Reputation: 2 056