How can exclude mounted CD's from my searches?

I am currently working on an AppleScript. Part of the script gets all the names of my Albums in iPhoto. I have been able to do that quite easily. (See below).
But I only want to get albums on hard drives (external or internal) and USB flash drives or sticks. I do not want to get the names of any albums on any mounted CD’s.

How can I exclude the CD’s. When I look at the properties of a CD, I don’t see anything that identifies it as a CD. There is the “ejectable” property but that also applies to USB flash drives etc.

any Ideas?

Rob

P.S. Here is the part of the script I am working on…

tell application “iPhoto”
repeat with Album_Number from 1 to (count albums)
if (count photos in album Album_Number) is greater than 0 then
set album_list to album_list & (name of album Album_Number)
end if
end repeat
end tell

This seems to work for me:

tell application "Finder" to set CD to name of disks where its group privileges is read only

hm, on my machine a few volumes have read only group privileges, but what’s about this

tell application "Finder" to set CD to name of disks whose free space is 0.0 and ejectable is true

Oddly enough (don’t understand why), those conditions don’t do it for me - ejectable is true by itself works, but finds my pen drive as well. Free space is true finds only “Network” on mm.

sometimes scripting can be really annoying :smiley:

This works but there must be an easier way… Rob

set CD to {}
tell application “Finder”
try
name of disks where (its group privileges is read only and ejectable is true)
set CD to name of disks where (its group privileges is read only and ejectable is true)
on error
set CD to {}
end try
end tell

OOps. I forgot to delete one line. This is what I wanted to post (smile). Rob

set CD to {}
tell application “Finder”
try
set CD to name of disks where (its group privileges is read only and ejectable is true)
on error
set CD to {}
end try
end tell

It’s not the fastest thing in the world, but this should give you a list containg the Volume Names of any/all CD/DVDs attached to your system… The script may need to be modified though depending on the Drive(s) in your system though that should be easily worked around if need be.

set VolName to {}
set disks to paragraphs of (do shell script "diskutil list | grep \"/dev\"")
repeat with aDisk in disks
	if (do shell script "diskutil info " & aDisk) contains "Drive Type:         CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-RW, DVD+R, DVD+RW" then
		set end of VolName to text 24 thru -1 of (do shell script "diskutil info " & aDisk & " | grep \"Volume Name:\"")
	end if
end repeat

Second version, this one only makes 1 shell call inside the repeat loop.

set cdID to "CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-RW, DVD+R, DVD+RW"
set VolName to {}
set disks to paragraphs of (do shell script "diskutil list | grep \"/dev\"")
repeat with aDisk in disks
	try
		set end of VolName to text 24 thru -1 of (do shell script "if diskutil info " & aDisk & " | grep -q \"" & cdID & "\"; then diskutil info " & ¬
			aDisk & " | grep \"Volume Name:\"; fi")
	end try
end repeat

Another variation on the same theme:


tell application "Finder" to set all_volume_names to name of disks
set CDDVD_volume_names to {}
repeat with i from 1 to length of all_volume_names
	try
		do shell script "diskutil info /Volumes/'" & (item i of all_volume_names) & "' | egrep 'Drive Type: +(CD-)|(DVD-)'"
		set end of CDDVD_volume_names to item i of all_volume_names
	end try
end repeat

Thanks for the attempt. I agree you may have to look at the /dev directory to really figure out which devices are CD or DVD drives.

But I can’t get your script to work. Many of my CD’s have Volume Name BLANK. So I get an empty list.

It looks like Mac OS X looks at the output of “diskutil list /dev/disk1”. The line with Apple_HFS has the Volume Name that is displayed on the Desktop.

But there must be an easier way.

Why does Apple make it so hard to figure out the type of device on which a Volume is loaded?

Rob

FYI – Here is the output of “diskutil info /dev/disk1”

robs-computer:~ rob$ diskutil info /dev/disk1
Device Node: /dev/disk1
Device Identifier: disk1
Mount Point:
Volume Name:

Partition Type: Apple_partition_scheme
Bootable: Not bootable
Media Type: DVD-ROM
Protocol: ATAPI
SMART Status: Not Supported

Total Size: 4.1 GB
Free Space: 0.0 B

Read Only: Yes
Ejectable: Yes
OS 9 Drivers: No
Low Level Format: Not Supported

Drive Type: CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-R, DVD-RW, DVD+R, DVD+RW
Media Type: DVD-R
Erasable: No

Here is the output of “diskutil list /dev/disk1”

robs-computer:~ rob$ diskutil list /dev/disk1
/dev/disk1
#: type name size identifier
0: Apple_partition_scheme *4.1 GB disk1
1: Apple_partition_map 31.5 KB disk1s1
2: Apple_HFS Mac Feb 13 2007 4.1 GB disk1s2

The volume name that appears on the desktop is “Mac Feb 13 2007”

Rob

So your CDs have no names…

I haven’t done any scripting with iPhoto before so lets say that a CD does have volume name of “Photo CD” how would you write your script in iPhoto to ignore it?

Perhaps if I understand that syntax I might have a better idea to work around your problem.

It really itsn’t accurate to say that my CD’s (burned using Apple’s Burn Folder in HFS+ format) don’t have Volume names. But for some reason, you can’t see them using the “diskutil info /dev/disk1” command. You can see them in the parition name when when do a “diskutil list /dev/disk1”… Very strange.

You also see the name if I do a “ls /volumes”. For example:

robs-computer:~ rob$ ls -la /Volumes
total 16
drwxrwxrwt 5 root admin 170 Feb 18 21:47 .
drwxrwxr-t 29 root admin 1088 Feb 18 08:00 …
-rwxrwxrwx 1 rob rob 82 Jan 13 20:49 ._ROB
drwxr-xr-x 32 rob rob 1088 Feb 13 19:28 Mac Feb 13 2007
lrwxr-xr-x 1 root admin 1 Feb 18 08:00 Macintosh HD → /

In this case, the volume name is “Mac Feb 13 2007”. So you would access a photo using “/Volumes/Mac\ Feb\ 13\ 2007/Photos/pic001.jpeg”

Rob

Rob,

The script I suggested utilizes volume mount points (“/Volume/VolumeName”-type values), not device node entries (“/dev/disk1”-type values), as the device parameter for the “diskutil info” command, and this does yield volume names as part of the “diskutil info” output. You may want to give it a try.

tell application "Finder" to set all_volume_names to name of disks -- > includes names of CDs and DVDs as seen on the desktop
set CDDVD_volume_names to {}
repeat with i from 1 to length of all_volume_names
   try
       do shell script "diskutil info /Volumes/'" & (item i of all_volume_names) & "' | egrep 'Drive Type: +(CD-)|(DVD-)'" -- > executes without an error for CDs and DVDs
       set end of CDDVD_volume_names to item i of all_volume_names
   end try
end repeat

bmose

I like it bmose, I didn’t think to grab the volumes via the finder… nice to find ways to speed up scripts :smiley:

One thing though it may be dependant on the CD/DVD , but I DO receive Volume Names when using “diskutil info” at the device level. I tried it with 3 cds and 2 dvds and recieved the volume name each time.

Hi James,

this does the same:

set all_volume_names to list disks 

Glad it worked!

bmose - Many thanks for ther script. A brilliant way to tackle this perplexing problem.

But I had some problems with your scriopt. It works most of the time but your script has a bug in it when it tries to handle names with forward slashes in them.

e.g. I have a CD with the Apple Volume name of “iPhoto Library - 04/02/07”. The trick is to convert this name into a UNIX name where the slashes are converted into colons using the POSIX path command.

e.g. POSIX path of ‘iPhoto Library - 04/02/07’ will result in a valid UNIX file name that diskutil can process (e.g. /Volumes/iPhoto Library - 04:02:07)

I have modified your script to use Posix Path.

tell application "Finder" to set all_volume_names to name of disks -- > includes names of CDs and DVDs as seen on the desktop
set CDDVD_unix_volume_names to {}
set CDDVD_apple_volume_names to {}
repeat with i from 1 to length of all_volume_names
	set item i of all_volume_names to POSIX path of item i of all_volume_names
	
	try
		do shell script "diskutil info '" & (item i of all_volume_names) & "'  | egrep 'Drive Type: +(CD-)|(DVD-)'" -- > executes without an error for CDs and DVDs
		set end of CDDVD_unix_volume_names to text 10 thru -1 of (item i of all_volume_names)
		set end of CDDVD_apple_volume_names to POSIX file (item i of all_volume_names) as string
	end try
end repeat

This script appears to handle all of my CD’s with names that have slashes in them.

I have created two variables CDDVD_unix_volume_names to hold the UNIX volume names and CDDVD_apple_volume_names to hold the Apple Mac Volume names.

Rob

Here is another variation of the script. Instead of returning Volume name, the script returns the unix and apple Volume Paths. In my view, this is more useful.

tell application "Finder" to set all_volume_names to list disks -- > includes names of CDs and DVDs as seen on the desktop
set CDDVD_unix_volume_paths to {}
set CDDVD_apple_volume_paths to {}
repeat with i from 1 to length of all_volume_names
	set item i of all_volume_names to POSIX path of item i of all_volume_names
	
	try
		do shell script "diskutil info '" & (item i of all_volume_names) & "'  | egrep 'Drive Type: +(CD-)|(DVD-)'" -- > executes without an error for CDs and DVDs
		set end of CDDVD_unix_volume_paths to text of (item i of all_volume_names)
		set end of CDDVD_apple_volume_paths to POSIX file (item i of all_volume_names) & ":" as string
	end try
end repeat