The FooDoo Lounge

Special Folders and the 'path to' command

Introduction

The path to command from the Standard Additions osax provides a fully portable mechanism for determining the location of special folders in the system. The line below will return an alias to the Scripting Additions folder on whatever machine is running it, regardless of the name of the volume/disk or the system language:

path to scripting additions
--> alias "MacHD:System:Library:ScriptingAdditions:" -- under OS X
--> alias "MacHD:System Folder:Scripting Additions:" -- under OS 8/9

The Standard Additions dictionary has never, as of this writing, provided a full list of the folders for which human language terms exist. That list, shown below, is itself a subset of the folders whose paths can be obtained using the path to command. This table was derived from Folders.h, a C header file found here on my machine. If you run OS X, clicking the link should reveal or open your own copy, depending on your browser settings.

The full list of folders is available by calling path to using four character codes from the table below. This produces the same result as the line above:

path to "ƒscr"

OS X also offers an extra parameter for path to, which takes into account the fact that there can be up to 4 versions of each special folder:

path to "ƒscr" from System domain
--> alias "MacHD:System:Library:ScriptingAdditions:" -- the default, which doesn't make much sense given that it's read only

path to "ƒscr" from local domain
--> alias "MacHD:Library:ScriptingAdditions:" -- scripting additions available to all users

path to "ƒscr" from user domain
--> alias "MacHD:Users:username:Library:ScriptingAdditions:" -- scripting additions available only to the current user

The fourth option (prior to AS 1.9.2, which shipped with 10.3) is from network domain, which I can't test. Check the Standard Additions Dictionary for the list.

AS 1.9.2 added a fifth option - from Classic domain - which allows access to the special folders in the nominated classic System Folder and the new option of not creating folders if they don't already exist.

Other Info

Returning Strings

It is common to use the result of a call to path to to build a path string, which requires a coercion to string from alias. This can be done in the usual way, but the command can return a string itself and this is measurably faster than a coercion:

path to "ƒscr" as string
--> "MacHD:System:Library:ScriptingAdditions:"

From somewhere around AS 1.8.3. or so, it is also possible to return the path as Unicode text.

Raw Event Syntax

It is also possible, though probably not necessary, to use AppleScript's raw syntax:

path to «constant ****pubb»
--> alias "Mac HD:Users:username:Public:"

This syntax will compile to a human understandable term if one exists:

path to «constant ****pref»

Compiles to:

path to preferences

Other Uses

As well as providing machine independent paths, path to has a few other functions:

path to me

The result of this varies depending on the context. If used in a script application, it will return the full path to the application, including its name. If used in Apple's Script Editor, it will return the path to the editor. Other editors, such as Script Debugger, allow it to return the path to the calling script. Apple's Script Menu returns the path to the System Events app, which is the process that runs all Script Menu scripts.

The main use for this command is to find resources that are in a known location relative to a script application. I've used it in installers for example.

It is also possible to use it to return the path of the current application:

path to current application

The result also varies depending on the context. I've used it in an application to get the name of the frontmost app in classic MacOS, but Script Editor (2.0b) will only return the path to itself, even after another app has been activated, so the behaviour may have changed in OS X.

Folder Table

Legend

Description is the comment from the header file
Full Form shows the human language term where applicable (tested under OS 10.2)
Code is the four character code that can be used in quotes, as shown above
Result under... show the resulting paths (strings are shown, but they're actually aliases) as they are on my machine

Errors:
(1) "Disk some object was not found" (number -35) -- misleading error from AS 1.4/OS9.0.4
(2) "Folder is not available in this operating system version." (number -43) -- OS X
(3) "Folder does not exist, and you don't have access privileges to create it." (number -5000) -- OS X

Notes

Be aware that AppleScript versions prior to 1.9.2 (OS 10.3) will create the folders called by the command if possible and if they don't already exist. This can lead to some whacky things, such as a 'Recent Applications' folder being created in the current user's folder in OS X if path to "rapp" is called. AS 1.9.2 added the boolean folder creation, which defaults to true for backward compatibility. If path to is called using without folder creation it returns error number -43 if the folder does not exist.

Not all of the OS X defaults make sense - path to "apps" - creates an 'Applications' folder in the current user account, instead of returning the main Applications folder, though it can be obtained by adding the from local domain parameter.

Kudos to the creative individual who created the Location Manager codes.

 

Description Full form Code Result under OS 9.0.4 Result under OS 10.2
the system folder path to system folder macs MacHD:System Folder: MacHD:System:
the desktop folder; objects in this folder show on the desk top. path to desktop desk MacHD:Desktop Folder: MacHD:Users:username:Desktop:
the desktop folder at the root of the hard drive, never the redirected user desktop folder   sdsk MacHD:Desktop Folder: MacHD:Users:username:Desktop Folder:
the trash folder; objects in this folder show up in the trash path to trash folder trsh MacHD:Trash: MacHD:Users:username:.Trash:
the trash folder at the root of the drive, never the redirected user trash folder   strs MacHD:Trash: Error (2)
the "empty trash" folder; Finder starts empty from here down   empt MacHD:Trash: MacHD:Users:username:.Trash:
Print Monitor documents path to printmonitor prnt MacHD:System Folder:PrintMonitor Documents: Error (3)
Finder objects (applications, documents, DAs, aliases, to...) to open at startup go here path to startup strt MacHD:System Folder:Startup Items: Error (2)
Finder objects (applications, documents, DAs, aliases, to...) to open at shutdown go here path to shutdown shdf MacHD:System Folder:Shutdown Items: Error (2)
Finder objects to put into the Apple menu go here path to apple menu amnu MacHD:System Folder:Apple Menu Items: Error (2)
Control Panels go here (may contain INITs) path to control panels ctrl MacHD:System Folder:Control Panels: Error (2)
System control panels folder - never the redirected one, always "Control Panels" inside the System Folder   sctl MacHD:System Folder:Control Panels: Error (2)
System extensions go here path to extensions folder extn MacHD:System Folder:Extensions: Error (2)
Fonts go here path to fonts folder font MacHD:System Folder:Fonts: MacHD:System:Library:Fonts:
preferences for applications go here path to preferences pref MacHD:System Folder:Preferences: MacHD:Users:username:
Library:Preferences:
System-type Preferences go here - this is always the system's preferences folder, never a logged in user's path to system preferences sprf MacHD:System Folder:Preferences: MacHD:System:Library:PreferencePanes:
temporary files go here (deleted periodically, but don't rely on it.) path to temporary items folder temp MacHD:Temporary Items: MacHD:private:tmp:501:Temporary Items:
    extD MacHD:System Folder:Extensions (disabled): Error (2)
    ctrD MacHD:System Folder:Control Panels (disabled): Error (2)
    macD MacHD:System Folder:System Extensions (Disabled): Error (2)
    strD MacHD:System Folder:Startup Items (Disabled): Error (2)
    shdD MacHD:System Folder:Shutdown Items (Disabled): Error (2)
  path to At Ease applications folder apps MacHD:Applications: MacHD:Users:username:Applications:
  path to At Ease documents folder docs MacHD:Documents: MacHD:Users:username:Documents:
root folder of a volume   root MacHD:MacHD: MacHD:System:
items deleted at boot   flnt MacHD:Cleanup At Startup: MacHD:private:tmp:501:Cleanup At Startup:
third-party items and folders path to application support folder asup MacHD:System Folder:Application Support: MacHD:Library:Application Support:
encoding tables   ƒtex MacHD:System Folder:Text Encodings: Error (3)
stationery path to stationery folder odst MacHD:Stationery: Error (3)
OpenDoc root   odod MacHD:System Folder:Editors:OpenDoc: Error (2)
OpenDoc Shell Plug-Ins in OpenDoc folder   odsp MacHD:System Folder:Editors:OpenDoc:OpenDoc Shell Plug-Ins: Error (2)
OpenDoc editors in MacOS Folder path to editors folder oded MacHD:System Folder:Editors: Error (2)
OpenDoc subfolder of Editors folder   ƒodf Error (1) Error (2)
OpenDoc libraries folder   odlb MacHD:System Folder:Extensions:OpenDoc Libraries: Error (2)
CKH general editors folder at root level of Sys folder   ƒedi Error (1) Error (2)
CKH help folder currently at root of system folder path to help folder ƒhlp MacHD:System Folder:Help: MacHD:Library:Documentation:Help:
CKH internet plug ins for browsers and stuff path to internet plugins folder ƒnet MacHD:System Folder:Internet Plug-Ins: Error (3)
CKH modem scripts, get 'em OUT of the Extensions folder path to modem scripts folder ƒmod MacHD:System Folder:Extensions:Modem Scripts: MacHD:System:Library:Modem Scripts:
CKH new folder at root of System folder for printer descs. path to printer descriptions folder ppdf MacHD:System Folder:Extensions:Printer Descriptions: MacHD:System:Library:Printers:PPDs:
CKH new folder at root of System folder for printer drivers path to printer drivers folder ƒprd MacHD:System Folder:Printer Drivers: Error (2)
CKH at root of system folder path to scripting additions folder ƒscr MacHD:System Folder:Scripting Additions: MacHD:System:Library:ScriptingAdditions:
CKH for general shared libs. path to shared libraries folder ƒlib MacHD:System Folder:Extensions: MacHD:System:Library:CFMSupport:
CKH macintalk can live here path to voices folder fvoc MacHD:System Folder:Extensions:Voices: MacHD:System:Library:Speech:Voices:
CKH for control strip modules path to control strip modules folder sdev MacHD:System Folder:Control Strip Modules: Error (2)
SJF for Assistants (MacOS Setup Assistant, etc)   astƒ MacHD:Assistants: Error (3)
SJF for Utilities folder   utiƒ MacHD:Utilities: MacHD:Applications:Utilities:
SJF for Apple Extras folder   aexƒ MacHD:Apple Extras: MacHD:Applications:Extras:
SJF for Contextual Menu items   cmnu MacHD:System Folder:Contextual Menu Items: MacHD:Library:Contextual Menu Items:
SJF for MacOS ReadMes folder   morƒ MacHD:Mac OS Read Me Files: Error (2)
EAS for Location Manager Module files except type 'thng' (within kExtensionFolderType)   walk MacHD:System Folder:Extensions:Location Manager Modules: Error (2)
EAS for Location Manager Preferences (within kPreferencesFolderType; contains kALMLocationsFolderType)   trip MacHD:System Folder:Preferences:Location Manager Prefs: Error (2)
EAS for Location Manager Locations (within kALMPreferencesFolderType)   fall MacHD:System Folder:Preferences:Location Manager Prefs:Locations: Error (2)
for ColorSync™ Profiles   prof MacHD:System Folder:ColorSync Profiles: MacHD:System:Library:ColorSync:Profiles:
for Theme data files   thme MacHD:System Folder:Appearance:Theme Files: Error (3)
Favorties folder for Navigation Services   favs MacHD:System Folder:Favorites: MacHD:Users:username:Library:Favorites:
Internet folder (root level of startup volume)   intƒ MacHD:Internet: Error (2)
Appearance folder (root of system folder)   appr MacHD:System Folder:Appearance: Error (3)
Sound Sets folder (in Appearance folder)   snds MacHD:System Folder:Appearance:Sound Sets: Error (3)
Desktop Pictures folder (in Appearance folder) path to desktop pictures folder dtpƒ MacHD:System Folder:Appearance:Desktop Pictures: MacHD:Library:Desktop Pictures:
Internet Search Sites folder   issf MacHD:System Folder:Internet Search Sites: MacHD:Users:username:Library:Internet Search Sites:
Find support folder   fnds MacHD:System Folder:Extensions:Find: MacHD:System:Library:Find:
Find by content folder   fbcf MacHD:TheFindByContentFolder: Error (3)
Installer Logs folder   ilgf MacHD:Installer Logs: MacHD:Library:Receipts:
Scripts folder path to scripts folder scrƒ MacHD:System Folder:Scripts: MacHD:Users:username:Library:Scripts:
Folder Actions Scripts folder path to Folder Action scripts folder fasf MacHD:System Folder:Scripts:Folder Action Scripts: MacHD:Users:username:Library:
Scripts:Folder Action Scripts:
Launcher Items folder path to launcher items folder laun MacHD:System Folder:Launcher Items: Error (2)
Recent Applications folder   rapp MacHD:System Folder:Apple Menu Items:Recent Applications: MacHD:Users:username:Library:Recent Applications:
Recent Documents folder   rdoc MacHD:System Folder:Apple Menu Items:Recent Documents: MacHD:Users:username:Library:Recent Documents:
Recent Servers folder   rsvr MacHD:System Folder:Apple Menu Items:Recent Servers: MacHD:Users:username:Library:Recent Servers:
Speakable Items folder path to speakable items spki MacHD:System Folder:Apple Menu Items:Speakable Items: Error (3)
Keychain folder path to keychain folder kchn MacHD:System Folder:Preferences:Keychains: MacHD:Users:username:Library:Keychains:
QuickTime Extensions Folder (in Extensions folder)   qtex MacHD:System Folder:Extensions:QuickTime Extensions: MacHD:System:Library:QuickTime:
Display Extensions Folder (in Extensions folder)   dspl MacHD:System Folder:Extensions:Display Extensions: Error (2)
Multiprocessing Folder (in Extensions folder)   mpxf MacHD:System Folder:Extensions:Multiprocessing: Error (2)
Printing Plug-Ins Folder (in Extensions folder)   pplg MacHD:System Folder:Extensions:Printing Plug-ins: Error (2)
The top-level of a Folder domain, e.g. "/System"   dtop Error (1) MacHD:System:
the Library subfolder of a particular domain   dlib Error (1) MacHD:System:Library:
Contains ColorSync-related folders   sync Error (1) MacHD:System:Library:ColorSync:
ColorSync CMMs   ccmm Error (1) Error (3)
ColorSync Scripting support   cscr Error (1) MacHD:System:Library:ColorSync:Scripting:
Contains Printing-related folders   impr Error (1) MacHD:System:Library:Printers:
Contains Speech-related folders   spch Error (1) MacHD:System:Library:Speech:
Contains Carbon-specific file   carb Error (1) Error (3)
Contains Documentation files (not user documents)   info Error (1) MacHD:Library:Documentation:
Contains Developer Documentation files and folders   ddoc Error (1) MacHD:Developer:Documentation:
Contains Developer Help related files   devh Error (1) MacHD:Developer:Documentation:Help:
Contains Developer Applications   dapp Error (1) MacHD:Developer:Applications:
Logs folder   logs Error (1) MacHD:Users:username:Library:Logs:
Contains Internet Search Sites downloaded from the Internet   issd Error (1) MacHD:Users:username:Library:Internet Search Sites:.Downloads:
Contains temporary items created on behalf of the current user   utmp Error (1) MacHD:private:tmp:501:
Contains various cache files for different clients   cach Error (1) MacHD:Library:Caches:
Contains MacOS X Framework folders   fram Error (1) MacHD:System:Library:Frameworks:
Contains MacOS X Private Framework folders   pfrm Error (1) MacHD:System:Library:PrivateFrameworks:
MacOS 9 compatible desktop folder - same as kSystemDesktopFolderType but with a more appropriate name for Mac OS X code.   sdsk MacHD:Desktop Folder: MacHD:Users:username:Desktop Folder:
Contains MacOS X Developer Resources   devf Error (1) Error (3)
Contains Mac OS X System Sound Files   ssnd Error (1) MacHD:System:Library:Sounds:
Contains Mac OS X components   cmpd Error (1) MacHD:System:Library:Components:
Contains QuickTime components for Mac OS X   wcmp Error (1) MacHD:System:Library:QuickTime:
Refers to the "CoreServices" folder on Mac OS X   csrv Error (1) MacHD:System:Library:CoreServices:
Refers to the "Pictures" folder in a users home directory   pdoc Error (1) MacHD:Users:username:Pictures:
Refers to the "Movies" folder in a users home directory   mdoc Error (1) MacHD:Users:username:Movies:
Refers to the "Music" folder in a users home directory   µdoc Error (1) MacHD:Users:username:Music:
Refers to the "Sites" folder in a users home directory   site Error (1) MacHD:Users:username:Sites:
Refers to the "Public" folder in a users home directory   pubb Error (1) MacHD:Users:username:Public:
Refers to the Audio support folder for Mac OS X   adio Error (1) MacHD:Library:Audio:
Refers to the Sounds subfolder of Audio Support   asnd Error (1) MacHD:Library:Audio:Sounds:
Refers to the Banks subfolder of the Sounds Folder   bank Error (1) MacHD:Library:Audio:Sounds:Banks:
Refers to the Alert Sounds subfolder of the Sound Folder   alrt Error (1) MacHD:Library:Audio:Sounds:Alerts:
Refers to the Plug-ins subfolder of the Audio Folder   aplg Error (1) MacHD:Library:Audio:Plug-Ins:
Refers to the Components subfolder of the Audio Plug-ins Folder   acmp Error (1) MacHD:Library:Audio:Plug-Ins:Components:
Refers to the Kernel Extensions Folder on Mac OS X   kext Error (1) MacHD:System:Library:Extensions:
Refers to the Directory Services folder on Mac OS X   dsrv Error (1) MacHD:Library:DirectoryServices:
Refers to the Directory Services Plug-Ins folder on Mac OS X   dplg Error (1) MacHD:Library:DirectoryServices:PlugIns:
Refers to the "Receipts" folder in Mac OS X   rcpt Error (1) MacHD:Library:Receipts:
Refers to the [domain]/Library/Filesystems folder in Mac OS X   fsys Error (1) MacHD:System:Library:Filesystems:
Refers to the [domain]/Library/Filesystems/
AppleShare folder in Mac OS X
  shar Error (1) MacHD:System:Library:
Filesystems:AppleShare:
Refers to the [domain]/Library/Filesystems/
AppleShare/Authentication folder in Mac OS X
  auth Error (1) MacHD:Library:Filesystems:
AppleShare:Authentication:
Refers to the MIDI Drivers folder on Mac OS X   midi Error (1) MacHD:Library:Audio:MIDI Drivers:
Refers to the [domain]/Library/KeyboardLayouts folder in Mac OS X   klay Error (1) MacHD:System:Library:Keyboard Layouts:
PKE for Locales folder   ƒloc MacHD:System Folder:Language & Region Support: Error (2)
Find By Content Plug-ins   fbcp MacHD:System Folder:Extensions:Find:Find by Content Plug-ins: Error (2)
Users folder, contains one folder for each user. path to users folder usrs MacHD:Users: MacHD:Users:
The folder for the currently logged on user. path to current user folder cusr Error (1) MacHD:Users:username:
The remote folder for the currently logged on user   rusf Error (1) Error (2)
The remote folder location for the currently logged on user   rusr Error (1) Error (2)
A Shared "Documents" folder, readable & writeable by all users   sdat MacHD:Users:Shared Documents: MacHD:Users:Shared:
Volume specific user information goes here   vsfd MacHD:TheVolumeSettingsFolder: Error (2)
Appleshare puts volumes to automount inside this folder.   srvƒ MacHD:System Folder:Servers: Error (2)
The "Applications" folder, pre Mac OS 9.1   åpps Error (1) Error (2)
The "Installer Logs" folder, pre Mac OS 9.1   îlgf Error (1) Error (2)
The "Assistants" folder, pre Mac OS 9.1   åstƒ Error (1) Error (2)
The "Utilities" folder, pre Mac OS 9.1   ütiƒ Error (1) Error (2)
The "Apple Extras" folder, pre Mac OS 9.1   åexƒ Error (1) Error (2)
The "Mac OS ReadMes" folder, pre Mac OS 9.1   µorƒ Error (1) Error (2)
The "Internet" folder, pre Mac OS 9.1   întƒ Error (1) Error (2)
The "Servers" folder, pre Mac OS 9.1   ßrvƒ Error (1) Error (2)
The "Stationery" folder, pre Mac OS 9.1   ødst Error (1) Error (2)
    relf Error (1) Error (2)
    spcf Error (1) Error (2)
    blsf Error (1) Error (2)
    rotf Error (1) MacHD:System:

 

The FooDoo Lounge is Copyright © Richard Morton 2002-2005

|| url: http://www.foodoo.sunreal.com.au/info/folders.html
|| created: 27-May-04, 2:51 PM; updated: 23-Aug-04, 6:20 PM
|| size: 72011 bytes