Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 900
P i Avatar asked Apr 24 '12 07:04

P i


2 Answers

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."

like image 173
mttrb Avatar answered Sep 22 '22 00:09

mttrb


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.

like image 31
geekosaur Avatar answered Sep 18 '22 00:09

geekosaur