The AppleScript command I think you're looking for is:
(path to Desktop Folder) as text
(path to Desktop Folder)
But that would return an HFS path and the code you posted is a POSIX Path so you could change it to:
set homePath to POSIX path of (path to Desktop Folder) as text
As stated in the comment there is
$USER for the terminal and per memory you can still call it in AppleScript with something like:
do shell script "$USER"
path to desktop folder doesn't work you can try just
path to desktop.
Addressing the comment. I was taught HFS path and alias path were the same, will make it another question for clarity.
Building the path
as text is a habit when concat strings or if I was going to take the path and call it later in a
do shell. For example:
(path to desktop folder)
in Script Debugger returns an HFS path. When you combine a directory as it was shown in the OP's question a compiling error occurs with:
(path to desktop folder & "foobar:")
(path to desktop folder) & "foobar:"
when I've called paths using
path to I've had to write them as:
(path to desktop folder as text) & "foobar:"
I was unfamiliar to
short user name of (system info) and
path to home folder but that's good to know. One issue with the question is the OP marks it with terminal and AppleScript so the solution is somewhat complicated.
~is shorthand for "the current user's home directory".
$USER, which contains the name of the home folder. So, you would write:
"/Users/$USER/My Folder", for example.
$HOMEin place of
~as it (
~) can be problematic, and it's recommended to use
$HOMEover it when using
do shell scriptin AppleScript.