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 reference 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.

Hey, so I tried it, I updated the line but this error still saying that the desktop couldn’t be found, any advise on that?

MAC Jotform
Desktop not found for _accessoryupdater
Shortcut creation attempted on all user desktops!

This is what I’m getting after updating it to the URL I need… now I’m deploying it through a MDM, does that interfere on something?

The script that I provided above was a replacement, not an addition to the script that you initially posted. That syntax:

USERSN=( $(/usr/bin/dscl . list /Users | grep -v ‘^_|guest|daemon|nobody|root’) )

removes all usernames beginning with ‘_’, so there is no means for that script to place the very first _accessoryupdate user name in the Bash array.

I don’t work in an MDM managed environment, nor have any MDM related adminstrative experience, so cannot say if MDM is causing interference. I do know that the script solution that I posted tests correctly on macOS Sequoia v15.1 and several previous versions of macOS not under MDM influence.

I tried it, and still giving me this accessoryupdate error, I’m doing it straight on the Mac’s console, I gave the file permissions and running it with sudo, but still shows that error

image

I have no means to test the script in an MDM environment. It works correctly here with identical code and produces a .webloc file on my Desktop. Thus, I cannot help further…

Thanks a lot for your help, I did try it on the laptop, I didn’t do it on the MDM… Any advise on running the script for it to succeed?

I have run the same script that I posted above on the following operating systems (unchanged) without failure to create the .webloc file on the Desktop:

  1. Sequoia v15.1.1
  2. Ventura 13.7.1
  3. Big Sur 11.7.10
  4. Mojave 10.14.6
  5. High Sierra 10.13.6
  6. El Capitan 10.11.6

The script does not need to be run with sudo. I even used the same script code as you posted and it worked fine. I recommend that you use a real editor such as BBEdit when writing shell script code. BBEdit 15 is free and still functional when the trial period is over. It requires macOS 11.6.7 or later. I never use the macOS pico editor for anything.

Copy and paste the script code I posted above into BBEdit and save as foo.sh. Mark it executable in the shell (chmod +x foo.sh), and then run it.

Otherwise, I cannot get the code to fail on the above systems and you may have a syntactical error like using fancy instead of straight quotes in Applescript.