Help with creating folders

Hey Guys,

Thanks for the help.

I’m trying to put together a script that will simply create a folder in a specific location. Problem is some of my machines / users don’t have the default name (Macintosh HD) for the drive. Is it possible to put a “wild card” at the beginning of my path.

Below is what an example of what I’m doing.

tell application “Finder”
make new folder at alias “Macintosh HD:Applications” with properties {name:“my folder”}
end tell

How can I make this script know to browse to applications if the root volume is not named Macintosh HD?


You probably do not want wildcards here (and there is no wildcard facilty, as such). What if there are backup volumes mounted? Does “*:Applications” pick “MacHD:Applications” or “External Drive:Applications”? What if the system is booted off of the external? What if other volumes have alternate installations of the OS (e.g. developers that need to test with 10.3, 10.4 and 10.5)?

The path to command is usually what someone would use if they wanted one of the system-specified folders (applications, library, temporary items, scripts, pictures, music, etc.).

If path to does not support the base folder you need, you might try using POSIX paths, since they do not incorporate the boot volume’s name.

(* Use "path to" from StandardAdditions.
 * There are many other standard folders available. Check the "path to" dictionary entry of StandardAdditions.
set appFolderAlias to path to applications folder from local domain

-- OR

(* Convert from a POSIX path.
 * Separate the string literal from the "POSIX file" designator. This keeps Script Editor from rewriting the "alias (POSIX file .)" syntax into a compile-time resolved alias object that will only work reliably on the machine on which it was compiled (this problem may have partially gone away on Leopard).
 * Since POSIX paths do not use the boot volume's name, they can be used to reference any file/directory on the current boot volume regardless of the boot volume's name. In the event that "path to" does not include the folder you need, this is a pretty good second choice.
set appFolderPosixPath to "/Applications"
set appFolderAlias to alias (POSIX file appFolderPosixPath)

-- Use the alias
tell application "Finder" to make new folder at appFolderAlias with properties {name:"my folder"}

Thats excellent.


Really appreciate it.