Getting the name of the hard disk?

my hard disk isnt called “Macintosh HD” so is there a way to get the name of the hard disk?


Does this do what you need? It gets the name of the startup disk, which should be ok unless you have multiple partitions or disks.

tell application "Finder" to set diskName to name of startup disk

Or, a Mac OS X-safe way:

path to startup disk
→ alias “Macintosh HD”

I took the request literally that the name of the hard drive was desired.

I tested the snippet on 10.2.4 - are there known bugs/issues when using OS X’s Finder to get the name of a startup disk?

thanks :smiley:

Quite simply, under Mac OS X, there’s no guarantee that the Finder is running and able to fulfill the request.

The Finder is only running when a user is logged in. If your script is run in the background it will fail if no user is logged in.

While you know the nature of your script and may be sure that the user will be logged in while running the script, it’s good practice to use System Events or other more-direct approaches.

Does this work for you?..

list disks
get item 1 of (list disks) --incase there is more than 1 HD