Posted on 12-13-2018 07:02 AM
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?
Solved! Go to Solution.
Posted on 12-13-2018 07:53 AM
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;
Posted on 12-13-2018 09:20 AM
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
Posted on 12-13-2018 07:27 AM
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.
Posted on 12-13-2018 07:42 AM
So what command should I have used to removed the shortcut from all users desktops? Or I guess any user that has the shortcut?
Posted on 12-13-2018 07:53 AM
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;
Posted on 12-13-2018 08:15 AM
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.
Posted on 12-13-2018 08:46 AM
You should be able add that to the script above and do both.
Posted on 12-13-2018 08:50 AM
I used the following in that script for the shortcut path for an alias for Calculator I created.
rm -f /Users/$TheUser/Desktop/Calculator
Posted on 12-13-2018 08:52 AM
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
Posted on 12-13-2018 09:20 AM
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
Posted on 12-13-2018 10:56 AM
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.
Posted on 12-13-2018 11:01 AM
How do you get you script to look right in posts?
Posted on 12-13-2018 11:13 AM
@Sobchak Use the little >_ button above where you create your comment.
Posted on 12-13-2018 11:19 AM
Thanks that looks much better. I wish hovering over all those button told you what they did.