I’m currently writing a script which requires a temporary file to be created, which stores some font information. Once the script has finished I would like to delete this file, preferably in a ‘behind-the-scenes’ fashion. I don’t want to move the file to the trash if possible - it looks and ‘feels’ messy.
I guess I’d really like to know if I can delete a file without the user knowing the file ever existed.
I’ve checked the Finder dictionary and Standard Additions but can’t see anything obvious.
I assume therefore that this can’t be done without an OSAX? It’s not a huge problem but I always favour Vanilla solutions where possible - and I nearly always forget to mention that in my posts!
The “Jon’s Commands” option seems the most favourable. Don’t have this on my mac anymore so I didn’t even think of it!
Sorry for the simple question - just like to keep you all on your toes!
You could consider using the temporary items folder instead of trying to delete your temp file.
If you save or write your temporary file to the temporary items folder (which is invisible), you can still read and write to it, and you needn’t worry about deleting it because that’s automatic when your application quits.
In other words, you’d be able to achieve your aim of writing a file, accessing it and having it deleted all behind the scenes and not loking and feeling messy - and all in vanilla AppleScript.
The Finder won’t be able to see it, but the read and write commands will.
The temporary items folder is gotten via “path to temporary items folder”
Your temporary file should delete itself when your application quits, it will definitely do so when your mac reboots. In any case, it’s all invisible to the user anyway.
This is exactly what I’m after! I don’t need the Finder to do anything with the file - I just need to write some data to a file which is read back in later in the script.
Having not done much scripting in the way of reading and writing files, using the Temporary Items Folder didn’t even occur to me!
I’ve just been testing out some code which writes the file to the Preferences folder, then erases the data at the end of the script by setting the EOF to 0. This leaves a zero K file in the Preferences folder, which I consider to be a better solution than having to use an OSAX. (Though I’m not sure if there are any nasty implications relating to the HFS system - ie. what happens to the chopped off data?)