Dynamic list of volumes

I’m working on a script to wake all of my hard drives from sleep before processing a backup script. This will make sure that all Applescript processes will run correctly and within the standard count times (rather than have the script run amiss while waiting for various disk volumes to spin-up).

I have eight different drives and as such volumes/drives act as backups, I set most of the volumes to spin-down. I’m planning on waking each of the hard drives from sleep by writing a 0 byte invisible file to each volume. All volumes must spin-up from sleep as the storing of files is not a cached procedure. I want the script to run through all of my hard disk names, set up paths to those volumes and then write the invisible file to each.

I can create a list to locate all of my volumes:

tell application "System Events" to set AllDisks to name of disks where it is local volume

I know how to set up one variable for one path:

set myDisk to quoted form of POSIX path of "Volumes:Archive I:"

I know that to successfully pull this off, I have to create some sort of repeat procedure to run through the list and assign the volumes to a variable (ie., myDisk(1) to POSIX path of “Volumes:” & AllDisks(1) - or something along those lines). I’m just not sure how to set this up.

The code for writing one invisible file to one volume looks as such:

set myDisk to quoted form of POSIX path of "Volumes:Archive I:"
do shell script "touch " & myDisk & ".wakey"

I prefer to create a list of volumes rather than hard-code each volume name into the script in case one of the volume names change, one is removed, etc.

I sincerely appreciate any help with this.

Model: PowerMac G4
AppleScript: 1.10.7
Browser: Firefox
Operating System: Mac OS X (10.4)


you can do it with this

tell application "System Events"
	repeat with oneDisk in (get disks whose local volume is true)
		do shell script "touch " & quoted form of (POSIX path of oneDisk & "/.wakey")
	end repeat
end tell

but I guess you can also read something to wake up the disk

AppleScript’s paths start directly with the disk, in your example “Archive I:”,
POSIX path coerces the string automatically to "/Volumes/Archive I/

Thanks, Stefan. This worked like a charm…and was much more simple than I thought! Excellent!

I’ve chosen to write the invisible file to each disk for two reasons:

  1. The file actually doesn’t take up any space at all
  2. This way I don’t ever have to worry about what file I’m actually reading on each volume…nor do I have to worry about placing such a file on any of my disks.

I tend to choose to use the POSIX path name of my volumes because I use non-standard character names in my volumes and I’m never sure how that translates when using a shell command.

Thanks for the shortcut about the coercion of volume names. I guess I’m being more safe than sorry when referencing volumes just in case there are duplicate names about.

this script reads each root directory of all local disks no matter what it contains

tell application "System Events"
	repeat with oneDisk in (get POSIX path of disks whose local volume is true and startup is false)
		do shell script ("ls -la " & quoted form of oneDisk)
	end repeat
end tell

It’s always strongly recommended to avoid non-standard characters in paths. :wink:

I usually dismount my backup disk when not in use, but here’s how I remount it when I want to do a backup:

do shell script "diskutil mount " & last word of (do shell script "diskutil list | grep ACB-External")

There is undoubtedly a neat way to combine those shell calls into one, but I didn’t know how to get the last word, so didn’t bother.

do shell script "diskutil mount `diskutil list | awk '/ ACB-External / {print $NF}'`"


Wunderbar ;), Thanks much.

I’ve found an alternative to awk (awk eludes me entirely):

do shell script "diskutil mount `diskutil list | grep ACB-External | grep -o '[^ ]*$'`"

The -o option shows only the part of the line matching the pattern
[^ ] matches any non-space character
[^ ]* matches zero or more non-space characters
$ anchors the statement at the end of the line, so it matches zero or more non-space characters at the end of the line; the node whose line contains the disk of the name in the previous grep.

There may be a way to combine these greps, but it hasn’t occured to me.