Skip to main content
Solved

Delete shortcut from all users desktops

  • December 13, 2018
  • 12 replies
  • 14 views

Forum|alt.badge.img+8

I ran a script that included: sudo rm ~/desktop/"skoolbo" It worked on 4 our of 5 of my test machines so I assumed that the command was correct, but I keep getting: Script result: rm: /var/root/desktop/skoolbo: No such file or directory

Why did the command work on some computers but not others, and what command should I have ran instead?

Best answer by dsavageED

As a script, something like:

#!/bin/bash
# create an array
_Users=( `ls /Users | grep -v "Shared"`)

echo ${_Users[@]}

# remove shortcut
for TheUser in ${_Users[@]}
do
rm -f /Users/$TheUser/TheShortcut
done

exit 0;

12 replies

Forum|alt.badge.img+1
  • New Contributor
  • 7 replies
  • December 13, 2018

Root is true super user account on the machine but it also has to be enabled so chances are the Root user was not configured to have that folder on the desktop or the Root user is not enabled.
To enable Root to check you would need to open and unlock the Directory Utility (can be found through Sys Prefs -> Users and Groups -> Login Items or Spotlight Search it).
Once the panel is unlocked you can find "Enable Root User" under the "Edit" option in the task bar and set a password.
Once its enabled reboot the computer and log in using the Username Root and the Password of your choosing.

It should be noted again that Root is a super user account and will not ask you to confirm passwords before making changes to the OS or System libraries so you can accidentally break a ton of stuff if you are not careful.


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 50 replies
  • December 13, 2018

So what command should I have used to removed the shortcut from all users desktops? Or I guess any user that has the shortcut?


dsavageED
Forum|alt.badge.img+8
  • New Contributor
  • 173 replies
  • Answer
  • December 13, 2018

As a script, something like:

#!/bin/bash
# create an array
_Users=( `ls /Users | grep -v "Shared"`)

echo ${_Users[@]}

# remove shortcut
for TheUser in ${_Users[@]}
do
rm -f /Users/$TheUser/TheShortcut
done

exit 0;

Forum|alt.badge.img+8
  • Author
  • Contributor
  • 50 replies
  • December 13, 2018

What about using:

#!/bin/sh
sudo rm -r /applications/"skoolbo.app"
sudo for /f %%a in ('dir /B /AD C:Users') do ( if exist "C:Users%%aDesktopskoolbo" del /F /Q "C:Users%%aDesktopskoolbo"
)

The goal is to remove the app and any desktop shortcuts that have been created.

I guess in my rush to find the answer I ended up grabbing a Windows script.


Forum|alt.badge.img+10
  • Contributor
  • 61 replies
  • December 13, 2018

You should be able add that to the script above and do both.


Forum|alt.badge.img+10
  • Contributor
  • 61 replies
  • December 13, 2018

I used the following in that script for the shortcut path for an alias for Calculator I created.

rm -f /Users/$TheUser/Desktop/Calculator

Forum|alt.badge.img+10
  • Contributor
  • 61 replies
  • December 13, 2018

So you might use something like this to do the app and the shortcut:

rm -f /Users/$TheUser/Desktop/MacKeeper
rm -f /Applications/MacKeeper.app

Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • December 13, 2018

Here is how you can remove a list of files from all user's desktops on the Mac.

#!/bin/bash

userList=$(/usr/bin/dscl . list /Users | grep -v "^_" | grep -v nobody | grep -v daemon | grep -v root)
fileNames=(
    file1
    file2
    file3
    file4
)

for userName in $userList; do
    userHome=$(/usr/bin/dscl . read "/Users/$userName" NFSHomeDirectory | awk '{print $2}')
    for fileName in "${fileNames[@]}"; do
        file="$userHome/Desktop/$fileName"
        if [[ -e "$file" ]]; then
            echo "$file exists; deleting."
            rm -Rf "$file"
        else
            echo "$file does not exist; skipping."
        fi
    done
done

exit 0

Forum|alt.badge.img+8
  • Author
  • Contributor
  • 50 replies
  • December 13, 2018

I ended up using:

#!/bin/bash
sudo rm -r /applications/"skoolbo.app"
# create an array
_Users=( `ls /Users`)

#echo ${_Users[@]}

# remove shortcut
for TheUser in ${_Users[@]}
do
    if [ -f "/Users/$TheUser/Desktop/skoolbo" ]; then
        sudo rm -f /Users/$TheUser/Desktop/skoolbo
        echo sudo rm -f /Users/$TheUser/Desktop/skoolbo
    fi
done

exit 0;

This seems to do what I need. Looking at some of your scripts maybe more echos would be useful though.


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 50 replies
  • December 13, 2018

How do you get you script to look right in posts?


Forum|alt.badge.img+18
  • Contributor
  • 475 replies
  • December 13, 2018

@Sobchak Use the little >_ button above where you create your comment.


Forum|alt.badge.img+8
  • Author
  • Contributor
  • 50 replies
  • December 13, 2018

Thanks that looks much better. I wish hovering over all those button told you what they did.