Temporary Folder Path for Apple Script

Solution 1:

Try this code:

set targetFile to quoted form of ((POSIX path of (path to temporary items)) & filename)

That will give you a proper POSIX path to the standard temporary folder. On my machine, for instance, this gave me:

'/private/var/folders/rl/zwlvv_hd6ss4c4yhb6nxxfz80000gn/T/TemporaryItems/<somefilename>'

I've used the quoted form of command in case the filename used contains a space or other special shell character.

You could also use System Events.app, like so:

tell application "System Events"
    set targetfolder to quoted form of (get POSIX path of file filename of temporary items folder)
end tell