LoginHook Script in Mojave / Catalina

Ironrob
New Contributor

Hey guys,

i installed a LoginHook Script in HighSierra, which delete user files from every Active Directory User, who logged in. It worked perfectly. Here is the script:

if [ -d "/Users/$USER" ]; then rm -R /Users/$1/Downloads/ rm -R /Users/$1/Documents/ rm -R /Users/$1/Desktop/ rm -R /Users/$1/Pictures/ rm -R /Users/$1/Movies/ rm -R /Users/$1/Music/ fi exit0

The script file was saved in /Library/Scripts/skript.sh. So i run as root in terminal:

sudo defaults write com.apple.loginwindow LoginHook /Library/Scripts/skript.sh

...and everything was fine. But since Mojave it doesn`t work anymore. I googled a lot, but canΒ΄t find my case.

Can anybody help me out? It should be for a school and a i need the script, because otherwise the 128 gb ssd would be pretty much game over! πŸ˜‰

1 REPLY 1

PaulHazelden
Contributor III

Hi Ironrob
Is this script, meant to simply clear space whilst leaving the account intact on the Mac? You seem to be not wiping the Users Library which is why I ask.
If so, you have found correct. OSX makes it almost impossible to delete those folders. But you can clear pretty much all of the contents of them. There are a few Apps that put files in the Documents file that are setup and operating files, and would need to be setup again.
You can put a after the / and this will leave the folders intact but empty their contents.
I would also use "" around the path rm -R "/Users/$1/Desktop"/
or rm -R /Users/"$1"/Desktop/* This will capture any issues with spaces etc that could get in there. We have had an issue here where User accounts managed to get a space added to the front of the home folder name. Not a clue how, but it happened, and with a space in there it made a similar script wipe the Users folder. You may find you need to use -Rf to force the contents to delete. As with everything, test it extensively, before you make it live.
You may also want to look at setting JAMF to clear the Users Cache files on Log out, if you are leaving the Library in place. User Cache files can build up.