Check for existence of loaded *blank* DVD?

Hello all,

I was wondering if someone has come up with a way of checking to see if a blank DVD is loaded in the DVD drive. I’ve written a few lines that can check if a DVD is in the drive in general:

set dvdlocation to "disk1"
	set disccheck to do shell script "diskutil list | grep " & dvdlocation
on error
	my WriteLog("There is no DVD in the computer, or it is not at " & dvdlocation & ".  This may be because there is another device, such as an external drive, hooked up.  You will need to change the definition of the \"dvdlocation\" variable in the Applescript." & return)

But this is sub-optimal, because a) the DVD may not always be at disk1 (I think if an external drive is connected before the DVD is loaded, it might become disk2, for instance), and b) it doesn’t check if the disc is blank. Knowing that blank DVDs show up in the Finder as “Untitled DVD”, I had hoped to maybe grep the mount list for “Untitled DVD” as the name of an existing volume, but apparently the “Untitled DVD” name that shows up in the Finder is only a pseudo-name, as it doesn’t show up in diskutil:

#: type name size identifier
0: Apple_partition_scheme *74.5 GB disk0
1: Apple_partition_map 31.5 KB disk0s1
2: Apple_HFS John 74.4 GB disk0s3
#: type name size identifier
0: *0.0 B disk1

and the disc doesn’t show up in /Volumes at all until after it’s formatted, so no help there either.

Any ideas?


it might be very easy: in PrefPane CDs & DVDs choose When you insert a blank DVD > Run script

That won’t work for our purposes, because I don’t want something happening right when the DVD is inserted. The scenario is that someone puts a blank DVD into the drive at, say, 4 PM, in preparation for the nightly backup that runs at 11 PM. If, at 11 PM, the Applescript auto-launches via cron and detects that someone has forgotten to put the DVD in, then it aborts and sends email. I suppose the “run script on DVD insert” could be used to create a temporary file somewhere that the script could check for, but that would be a really scary and quite fragile setup, I think.

You can either run a script triggered as described before
which can set a property (e.g a script object):

script blankDVDstatus
	property DVDinserted : false
end script
set blankDVDstatus's DVDinserted to true
store script blankDVDstatus in file (path to scripts folder as Unicode text) & "blankDVDstatus.scpt" with replacing

The backup script can check the status and reset the property

script blankDVDstatus
	property DVDinserted : false
end script

set thePath to (path to scripts folder as Unicode text) & "blankDVDstatus.scpt"
set blankDVDstatus to load script file thePath
if blankDVDstatus's DVDinserted then
	-- make backup
	set blankDVDstatus's DVDinserted to false
	store script blankDVDstatus in file thePath with replacing
	-- send email
end if

or, much easier with

checkBlankDVD() -- true, if a blank CD/DVD inserted

on checkBlankDVD()
		do shell script "diskutil list | grep '0.0 B'"
		return true
	on error
		return false
	end try
end checkBlankDVD

Aha! That last way is what I was looking for; I had forgotten that diskutil lists the size, and the DVD should be the only 0 byte device present. That’ll actually do nicely. Thanks, Stefan!