P i
P i

Reputation: 30724

OSX: API for retrieving path to user's ~/temp folder

Does OS X have a separate temp folder for each user?

If so, how to retrieve the temp folder path for the current user programmatically?

PS Looking at my own OS X file system, I can't see such a folder.

Upvotes: 7

Views: 9642

Answers (2)

geekosaur
geekosaur

Reputation: 61449

OS X does not (or did not, through early Lion releases; 10.7.3 seems to do so) set TMPDIR for use by Unix-like scripts or programs, but many GUI programs make use of a per-user temporary directory under /var/folders which you can retrieve using some AppleScript (temporary items folder in Scripting Additions) or via NSTemporaryDirectory() as noted elsewhere.

Upvotes: 2

mttrb
mttrb

Reputation: 8345

Assuming you are using Objective-C and Foundation: NSTemporaryDirectory() should return an NSString with the users temporary directory. On my machine that directory is under /var/folders/.

For example:

NSString *tempDirectory = NSTemporaryDirectory();

The documentation says that NSTemporaryDirectory() returns "the path of the temporary directory for the current user. If no such directory is currently available, returns nil."

Upvotes: 6

Related Questions