This script returns both POSIX and HFS paths–it is based on a suggestion by Shane.
set folderLocation to "~/Test Folder"
if folderLocation begins with "~" then set posixPath to (POSIX path of (path to home folder)) & text 3 thru -1 of folderLocation --> "/Users/Robert/Test Folder"
if folderLocation begins with "~" then set hfsPath to (POSIX file ((POSIX path of (path to home folder)) & text 3 thru -1 of folderLocation)) as text --> "Macintosh HD:Users:Robert:Test Folder:"
Just for the sake of completeness:
use framework "Foundation"
use scripting additions
set folderLocation to "~/Test Folder"
set folderLocation to current application's NSString's stringWithString:folderLocation
set posixPath to folderLocation's stringByExpandingTildeInPath() as text --> "/Users/Robert/Test Folder"
set hfsPath to (current application's |NSURL|'s fileURLWithPath:posixPath) as text --> "Macintosh HD:Users:Robert:Test Folder:"
I have an AppleScript library that handles this for you:
There is an undocumented function called makeFileReference Which converts anything (POSIX path string, HFS string, alias, etc.) into a file reference you can use.