Temporary Folder Path for Apple Script
Try this code:

set targetFile to quoted form of ((POSIX path of (path to temporary items)) &amp; 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/&lt;somefilename&gt;'


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