Saturday, January 16, 2021

#1 2006-06-15 09:27:52 am

bmose
Member
From:: Massachusetts
Registered: 2006-01-03
Posts: 343

Trying to get the volume name of the currently mounted CD or DVD

My goal is to get the volume (disk) name of the currently mounted CD or DVD.  I have written an Applescript that achieves this goal using a combination of "do shell script" and some text processing of the result of that command.  The comments within the script explain how it works.  I would like to ask two questions:

1) Is there a simpler, more direct, and/or more elegant way of getting the volume name than the "do shell script" method I have used?  For example, is there a volume or drive property that is unique to optical disks as opposed to hard drives, network drives, flash drives, etc, that would allow me to home in on the volume name directly?

2) If the answer to #1 is no, then I would like to ask a question about "grepping" (with which I have little expertise).  The result of my "do shell script" is a single line of the form

        "   Volume Name:             CD_or_DVD_Disk_Name"

        I have used repeat loops to remove "Volume Name:" and any leading and trailing blanks, because I couldn't figure out the proper grep command that would achieve the same result.  Could someone please suggest a simple grep command that would extract CD_or_DVD_Disk_Name from the line?

Thank you in advance for any help.

Applescript:


-- "drutil status" generates information on the currently mounted CD or DVD, including its "/dev/disk" value
-- The output of "drutil status" is "egrep"ed to obtain that "/dev/disk" value
-- "diskutil info" utilizes that "/dev/disk" value to generate further information on the currently mounted CD or DVD, including its volume name
-- The output of "diskutil info" is "egrep"ed to obtain the line containing that volume name

set s to (do shell script "diskutil info $(drutil status | egrep -ow '/dev/disk[0-9]') | egrep 'Volume Name:'")

-- The following repeat block takes the output from the shell script and finds the offset of the start of the name of the CD or DVD by skipping over "Volume Name:" and any leading blanks

repeat with m from ((offset of "Volume Name:" in s) + 12) to (length of s)
   if text item m of s is not " " then exit repeat
end repeat

-- The following repeat block takes the output from the shell script and finds the offset of the end of the name of the CD or DVD by skipping over any trailing blanks

repeat with n from (length of s) to 1 by -1
   if text item n of s is not " " then exit repeat
end repeat

-- The name of the CD or DVD is then extracted using the starting and ending offsets derived from the repeat blocks

set disk_name to (text items m thru n of s) as text

Offline

 

#2 2006-06-15 09:54:08 am

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4666

Re: Trying to get the volume name of the currently mounted CD or DVD

I use this to identify a CD from among the other volumes

Applescript:

tell application "Finder"
   set cds to {}
   set d to disks
   repeat with aDisk in d
       if size of aDisk < 1.0E+8 then set end of cds to name of aDisk
   end repeat
end tell

:


Mac mini running 10.14.6, 2011 27" iMac as display.


Filed under: Finder

Offline

 

#3 2006-06-16 09:03:52 am

bmose
Member
From:: Massachusetts
Registered: 2006-01-03
Posts: 343

Re: Trying to get the volume name of the currently mounted CD or DVD

Thank you for the suggestion.  It seems that this will not work for DVDs.  It might also run into trouble with flash drives, if I understand it correctly.  Any ideas on how to identify DVDs?

Offline

 

#4 2006-06-16 10:52:34 am

bmose
Member
From:: Massachusetts
Registered: 2006-01-03
Posts: 343

Re: Trying to get the volume name of the currently mounted CD or DVD

Jacques, thank you for your suggestion.  It works very well.  In the meanwhile, I did work out a "sed" method of extracting the volume name, and it seems to execute more quickly (about 1 second) than the "awk" method (about 5 to 10 seconds):

Applescript:

do shell script "diskutil info $(drutil status | egrep -ow '/dev/disk[0-9]') | egrep 'Volume Name:' | sed -E 's/^( *Volume Name: +)(.+)( *)$/\\2/'"

I take it from the responses of two experts that there is no direct and easy way to get the volume/disk name of a mounted CD or DVD.  So it seems that "do shell script" may be the way to go.

Offline

 

#5 2011-10-23 01:52:57 am

mapleridge
Member
Registered: 2008-11-27
Posts: 13

Re: Trying to get the volume name of the currently mounted CD or DVD

I'm having the same problem and, since this is an ancient thread, am wondering, whether anybody has come up with a better way to do this in the meantime?
Just FYI: I'm trying to cook up a script to rip/convert DVDs using HandbrakeCLI. The converted files are supposed to be placed in a folder named after the DVD volume name. Hence the task to fetch the DVD name.

Thanks in advance.

Konrad

P.S.: Just to avoid any copyright discussions, the DVDs I'm converting have been self-produced by myself, live gigs by my band.

EDIT: I just stumbled across the problem of automatically determining the path to the inserted DVD. This works just fine:

Applescript:

tell application "Finder"
   set the_dvd to choose folder -- choose the dvd disk
   set the_dvd to POSIX path of (the_dvd as text)
end tell

But it requires manual work, we don't want that. smile
I don't want to do it with folder actions, I just want to be able to pop in a DVD and start a script. If I could get this to work, I could probably even extract the name of the DVD from the resulting string, so my above mentioned problem would be addressed, as well. Two birds -> one stone! cool

Last edited by mapleridge (2011-10-23 03:41:01 am)


Filed under: mount, encode, DVD, Rip

Offline

 

#6 2021-01-11 10:12:18 pm

bachelorbob
Member
Registered: 2021-01-12
Posts: 1

Re: Trying to get the volume name of the currently mounted CD or DVD

bmose wrote:

Jacques, thank you for your suggestion.  It works very well.  In the meanwhile, I did work out a "sed" method of extracting the volume name, and it seems to execute more quickly (about 1 second) than the "awk" method (about 5 to 10 seconds):

Applescript:

do shell script "diskutil info $(drutil status | egrep -ow '/dev/disk[0-9]') | egrep 'Volume Name:' | sed -E 's/^( *Volume Name: +)(.+)( *)$/\\2/'"

I take it from the responses of two experts that there is no direct and easy way to get the volume/disk name of a mounted CD or DVD.  So it seems that "do shell script" may be the way to go.



I was looking for an AppleScript that would allow me to determine the /dev/disk# of an optical drive with a disc inserted, where the disc was not mounted.  (My iTunes occasionally unmounts a CD after I use the "Get Track Names" feature.)  With that disk#, I could then mount the disc, all without leaving iTunes, via my added scripts menu.  From the above example, I created this:

Applescript:


set disk_number to ""
do shell script "diskutil info $(drutil status | egrep -ow '/dev/disk[1-9]') | egrep 'Device Identifier:' | sed -E 's/^( *Device Identifier: +)(.+)( *)$/\\2/'"
set disk_number to result
try
   tell application "Finder" to do shell script "diskutil mount " & disk_number
end try

A little slow, but effective.

Model: MacBook Pro (mid-2012)
Browser: Safari 537.36
Operating System: macOS 10.13

Offline

 

#7 2021-01-12 12:47:29 pm

Mark FX
Member
From:: UK
Registered: 2011-08-12
Posts: 100

Re: Trying to get the volume name of the currently mounted CD or DVD

This  simple "System Events" code use to work, but I don't have a CD Disk at hand to test it with.
So I'm not sure if this code is still usable.

Applescript:


tell application "System Events" to get the name of every disk whose ejectable is true -- All Ejectable Volumes CD's DVD's Floppy Drives etc.

Just tested when I got home, and found it lists all removable volumes including USB drives.
So no good for the original OP's question, so apologies.

Regards Mark

Last edited by Mark FX (2021-01-12 02:14:13 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)