Ok, so now I found the
current application's NSTemporaryDirectory()
command I now have this just to try to create a temporary directory like the others you will find in the folder:
log current application's NSTemporaryDirectory()
log NSURL's URLWithString_((current application's NSTemporaryDirectory())as string & "com.RichardBirkett.DialogMaker/")
log (NSFileManager's defaultManager())'s URLForDirectory_inDomain_appropriateForURL_create_error_(99, 1, NSURL's URLWithString_((current application's NSTemporaryDirectory())as string & "com.RichardBirkett.DialogMaker/"), true, missing value)
If you look in the T folder or equivalent for you, there are many folders named after app IDs, and like the log says there is a folder called “…document being…”. I followed the note in the NSFileManager docs for creating a temporary folder, I had tried a simple URL but it ended up in the build folder.
OK I’ve been in this situation before and usually it helps to scrap that (but you can see what I’m trying to do). So- how do I create a temporary directory in the tmp folder that will be wiped when the app quits?
Be aware that NSTemporaryDirectory() is a function, not a method. That means if you use it, your app won’t work under Snow Leopard.
You have to delete it yourself. Files in the temp folder are automatically deleted periodically – not when the app that created them quits.
I thinking too Objective-C here I think, all I need is the temporary directory and to make new folder called what I want, which will hopefully get deleted automatically but not when I’m using such files. Thanks for the heads up too, I read there was an AppleScript equivalent, you probably said it, will it definitely be the same?
Edit: and you did :lol: ‘path to temporary items’ ← that.
Is there any important difference between the NSTemporaryDirectory and the ‘path to temporary items’ folder which is the /TemporaryItems folder within the ‘temporary directory’. Does the -items folder get emptied in a different way?
More problems related to this.
log valstatelogpath – /private/var/folders/m2/h4n6xbmx70xdz1hz9gx9yvfc0000gn/T/com.RichardBirkett.DialogMaker/StateLog.plist
log (valemaildata’s writeToFile_atomically_(valstatelogpath, true)) – 0
The folder exists but the file doesn’t however I successfully wrote to a file in the desktop before that hadn’t already been there, why is it failing/returning 0?
With what you’re showing us, it’s impossible to tell. What’s valemaildata? If it is NSData, use writeToFile:options:error: instead and get the error.
Thanks for replying so soon
It is an NSDictionary of NSMutableDictionaries, forgot to mention that, and that message has been sent with 1 returned before using the desktop folder like I said, so no worries about the dictionary being valid, I will paste a log of it if you like.
Edit I just realised why you’re asking and it is working with a blank dictionary slaps head sorry, I’ll get back to you on this.
Hmm, … Shane, did you mean to say that, or something different?
The function NSTemporaryDirectory() does work under Snow Leopard!?
[CORRECTION: Sorry! I now realize that you meant that it won’t work from AppleScriptObjC, which is true. I only tested it natively in ObjC, where it works of course.]
For URLs (which is the recommended way according to “Creating Paths and Locating Directories”), there is no simple alternative to NSTemporaryDirectory() – there is only a complicated thing using the method URLForDirectory:inDomain:appropriateForURL:create:error: (not the simpler URLsForDirectory:inDomains:).
AS: path to “temp” as text gives:
[u]ObjC string function:[/u] [b]NSTemporaryDirectory()[/b] gives:
(where /var is actually a link to /private/var, so it's the same thing except for the last "TemporaryItems".)
[u]ObjC URL based:[/u] [b][[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL: [i]anURL[/i] create:NO error:NULL]);[/b]
where [i]anURL[/i] is any non-nil URL, such as [b][[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0][/b]
and this gives:
if the app that called the method is named “Command Line Tool”.
(And I do note that the directory is created no matter what the create parameter is (YES or NO), and a new directory with a number appended is created each time you run it, even if the create parameter is NO!)
Hmm, I can’t resist thinking that it becomes a bit “code heavy” in order to comply with the recommendations and be URL oriented, and thereby modern…
I just truncated the path to temporary items and added my own folder named after my app to dump stuff in.
That’s right. And there’s no reason why one can’t keep using POSIX path of (path to temporary items). The key is to get it just once, and keep using the same path.