Temporary Folder Path for Apple Script set targetFile to (path to temporary items as string) &amp; fileName


I am trying to download a web image to temporary folder by curl in a Apple Script.

According to the above code, the curl downloads it as correct but the targetFile is currently as:

Macintosh HD:private:var:folders:...TemporaryItems:image.png


But after download, I need the downloaded image path as a correct file path like:

/tmp/image.png


How can I set targetFile as a string that have slash containing file path? Or how can I get the file path of the image after it is downloaded by curl?
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