The commonpath( function returns the path for common folders (desktop, library, documents, pictures, etc.).
This function has one parameter:
folder – The name of the common folder: application, library, document, desktop, appsupport, movies, music, pictures, cache or trash. The name may be specified in upper or lower case.
This function returns the path for common folders (desktop, library, documents, pictures, etc.). In this function, the folder name is always specified in English, but the correct path name will be returned even if the computer is set up in a non-English language. Here are some examples:
commonpath("desktop") ☞ /Users/joeuser/Desktop commonpath("appsupport") ☞ /Users/joeuser/Library/Application Support
Note: This function will return the correct path, but it isn’t guaranteed that the folder exists. To make sure, use the makefolder statement.
Advanced Note: The folder parameter can be specified as a number instead of as text. In that case, it must be a NSSearchPathDirectory constant. See Apple’s Foundation Constants Reference for more information.
The commonpath( function uses Apple’s NSSearchPathForDirectoriesInDomains( function. If you are really advanced, you can add a second parameter to the commonpath( function. This second parameter must be an integer according to the specifications for NSSearchPathDomainMask constants. Again, see Apple’s Foundation Constants Reference for more information. If you use this option, it is possible for the commonpath( function to return multiple paths. In that case, paths will be separated by a carriage return. If this second parameter is ommitted, NSUserDomainMask (1) is assumed. Here is an example that returns all current application folders.
This function will return mutiple lines, like this:
/Users/joeuser/Applications /Applications /Network/Applications
Essentially, you have full access to the
NSSearchPathForDirectoriesInDomains( function, just as if you were programming in Objective-C or Swift.
|10.0||New||New in this version.|