I think this should work on both 9 & X systems:
set temp_file to ((path to temporary items) as text) & "_Temp_"
Although the path to which it resolves will be different depending on the system. The only caveat to this (which may be a benefit) is that these files are flushed automatically by the system on restart/logouts. If you want your file to be more persistent, then the Preferences folder is OK but you’re probably better off with the Application Support Folder.
I use this script based on Rob’s terrific work to help me when I’m working with paths. You can save it as a script and add it to the Script Menu:
property routine_name : "set path to special folder"
-- Based on "Show Path Command" Version 1.0.2 by Rob Jorgensen
property folder_codes : {"- System -", "root", "macs", "dtop", "rotf", "", "- System Library -", "dlib", "?lib", "sync", "prof", "cscr", "cmpd", "csrv", "kext", "fsys", "shar", "fnds", "font", "fram", "klay", "?mod", "sprf", "impr", "ppdf", "pfrm", "qtex", "wcmp", "?scr", "ssnd", "spch", "fvoc", "", "- Computer -", "apps", "aex?", "uti?", "ddoc", "devh", "utmp", "temp", "flnt", "usrs", "sdat", "", "- Computer Library -", "asup", "adio", "midi", "aplg", "acmp", "asnd", "alrt", "bank", "cach", "cmnu", "dtp?", "dsrv", "dplg", "info", "?hlp", "auth", "indx", "rcpt", "ilgf", "empz", "", "- User -", "cusr", "desk", "sdsk", "trsh", "empt", "docs", "favs", "fbcx", "issf", "issd", "kchn", "mang", "pref", "rapp", "rdoc", "rsvr", "scr?", "fasf", "mdoc", "?doc", "pdoc", "pubb", "site"}
property item_delim : "-----------------------------------------------------------"
property folder_headers : {"All Special Folders", item_delim}
copy {folder_headers, {"false", item_delim}, ""} to {the_folders, invalid_choices, return_string}
set the_codes to folder_headers & folder_codes
set code_count to (count of the_codes)
repeat with i from 3 to code_count
set the_code to (item i of the_codes)
try
copy (the_code & " = " & tab & ((path to the_code as string) & return)) to end of the_folders
on error
copy the_code & return to end of the_folders
if the_code is not "All Special Folders" then
if the_code is not in invalid_choices then copy the_code & return to end of invalid_choices
end if
end try
end repeat
tell application "Script Editor"
activate
repeat
set chosen_code to (choose from list the_folders with prompt "Choose Special Folder:" cancel button name "Cancel" OK button name "Copy to Clipboard" with empty selection allowed without multiple selections allowed) as string
if chosen_code is in invalid_choices then
beep
display dialog "You made an invalid selection. Please try again." buttons {"OK"} default button 1 with icon 2
else
exit repeat
end if
end repeat
if chosen_code = "All Special Folders" then
set the_codes to folder_codes
else
set the_codes to {(text 1 thru 4 of chosen_code)}
end if
set the_button to button returned of (display dialog ("Set the path(s) to properties?") buttons {"No", "Yes"} default button 2 with icon 1)
end tell
set code_count to (count of the_codes)
repeat with i from 1 to code_count
set the_code to (item i of the_codes)
try
set the_path to (path to the_code) as string
my atid(":")
set folder_name to text item -2 of the_path
my atid("")
set folder_name to snr(folder_name, " ", "_")
if the_button = "Yes" then
set return_string to return_string & ("property path_to_" & folder_name & " : (path to " & the_code & ") as string") & return
else
set return_string to return_string & ("set path_to_" & folder_name & " to (path to " & the_code & ") as string") & return
end if
end try
end repeat
set the clipboard to return_string
tell application "Script Editor"
activate
display dialog ("The path to ?" & chosen_code & "? has been placed on clipboard. You may now paste it into a script window.") buttons {"?"} default button 1 with icon 1 giving up after 5
end tell
return return_string
on atid(the_delim)
set AppleScript's text item delimiters to the_delim
end atid
on snr(the_string, search_string, replace_string)
my atid(search_string)
set the_string to (every text item of the_string) as list
my atid(replace_string)
set the_string to (every text item of the_string) as string
my atid("")
return the_string
end snr
Jon