There's no reason not to use home directory notation, but there are a few pitfalls.
-------------------------------------------------------------------------------------------
# Input: a home directory based path ~/<path>, a full posix path, an alias, or a string.
# Output: a quoted posix path or a quoted string.
-------------------------------------------------------------------------------------------
on qt(_data)
if (class of _data) = alias then set _data to POSIX path of _data
if _data starts with "~" then
if length of _data > 2 then
tell _data to (text 1 thru 2) & quoted form of (text 3 thru -1)
return result
else
return _data
end if
else
return quoted form of _data
end if
end qt
-------------------------------------------------------------------------------------------
# Create test folder.
set _folder to ((path to desktop folder as text) & "Code Projects:")
tell application "Finder"
if not (folder _folder exists) then
set newFl to make new folder at desktop with properties {name:"Code Projects"}
set label index of newFl to 2
reveal _folder
end if
end tell
set tildePath to "~/Desktop/Code Projects/"
set fullPath to do shell script "echo " & tildePath
--> "/Users/myUser/Desktop/Code Projects/"
do shell script "open " & tildePath
--> The file /Projects does not exist.
do shell script "open " & quoted form of tildePath
--> The file /~/Desktop/Code Projects does not exist.
tell tildePath to (text 1 thru 2) & "\"" & (text 3 thru -1) & "\""
set tildePath to result
do shell script "open " & tildePath
--> Works
do shell script "open " & fullPath
--> The file /Projects does not exist.
do shell script "open " & quoted form of fullPath
--> Works
do shell script "open " & qt(tildePath)
-------------------------------------------------------------------------------------------
set _text to qt(text 2 thru -2 of "
01 Now is the time for all good men to come to the aid of their country.
02 Now is the time for all good men to come to the aid of their country.
03 Now is the time for all good men to come to the aid of their country.
")
set _dir to "~/Desktop/Test Path with Spaces/"
set cmd to "
P=" & qt(_dir) & ";
mkdir \"$P\";
open \"$P\";
"
do shell script cmd
set _file to _dir & "Text File.txt"
set cmd to "echo " & _text & " > " & qt(_file)
do shell script cmd
set _file to _dir & "Ferrari.html"
set cmd to "curl -L --user-agent 'Opera/9.70 (Linux ppc64 ; U; en)' " & _url & " -o " & qt(_file)
do shell script cmd