Getting error -1728 while running script

Hello there!

I am new on scripting, I created one to create a shortcut from website straight to the Desktop but every time I run it keeps giving the same error: 37:178: execution error: Finder got an error: Can’t get folder “/Users/administrator/Desktop”. (-1728)
Here’s the script:
#!/bin/bash

Jotform URL

url=“Link”

Loop through all user directories in /Users

for user in /Users/*; do
# Check if it’s a directory and the user profile is not a system folder (like Shared or Guest)
if [ -d “$user” ] && [ -d “$user/Desktop” ] && [ “$(basename $user)” != “Shared” ] && [ “$(basename $user)” != “Guest” ]; then
desktopPath=“$user/Desktop”
shortcutPath=“$desktopPath/Submit Ticket.webloc”

    # Check if the desktopPath exists (in case it's not there)
    if [ -d "$desktopPath" ]; then
        # Create the .webloc file using AppleScript with sudo to ensure elevated permissions
        sudo osascript -e "
        tell application \"Finder\"
            make new internet location file at folder \"$desktopPath\" to \"$url\"
        end tell
        "

        echo "Shortcut created on $user's Desktop"
    else
        echo "Desktop not found for $user"
    fi
fi

done

echo “Shortcuts created on all user desktops!”

Can someone please help me? I’m deploying this through and MDM but I’ve been testing and keeps failing

In general, AppleScript expects HFS-style paths or file references (or aliases), not POSIX paths.

You can convert a POSIX path to a file object using POSIX file "/PATH/TO/FILE". The reverse operation is POSIX path of file_reference.

Your problematic line can be changed to:

make new internet location file at folder (POSIX file \"$desktopPath\") to \"$url\"

Here is another approach to creating that Internet Location File on the user’s Desktop.

#!/bin/bash

# ignore (-v) these user names when adding to Bash array
USERSN=( $(/usr/bin/dscl . list /Users | grep -v '^_|guest|daemon|nobody|root') )
url="https://apple.com"

for u in $USERSN;
do
    desktopPath="/Users/$u/Desktop"
    if [[ -d "$desktopPath" ]]; then
        /usr/bin/osascript <<-AS
        use scripting additions
        
        tell application "Finder"
           make new internet location file at folder POSIX file "$desktopPath" as alias to "$url"
        end tell
AS
        echo "Shortcut created on $u's Desktop"
    else
        echo "Desktop not found for $u"
    fi
done
exit 0

This tests correctly on macOS Sequoia v15.1.