03-09-2023 05:47 AM - edited 03-09-2023 05:47 AM
Hi all,
My goal is to delete any files or folders on the desktop when the user logs out.
I'm using this command in bash script: rm -Rf /Users/<currentuser>/Desktop/*
The sript is set to run at logout.
Unfortunately it does not work.
When I try the command in the users Terminal it prompts "sure you want to delete all X files in /Users/<currentuser>/Desktop [yn]?"
According to this post under Jamf Pro the script should work if the script is set to run at 'startup', but this option is not available in Jamf School.
Is there any way to get it to work?
Posted on 03-09-2023 07:16 AM
Does the Guest Account meet your needs?
Posted on 03-10-2023 02:18 AM
No. Would have been nice if it did but unfortunatly it doesn't in this case.
03-09-2023 08:13 AM - edited 03-09-2023 08:18 AM
It works when I type in rm -Rf /Users/accountname/Desktop/* and set it to run at logout.
There are a few things to consider however: I had to give the bash application permission for Full Disk
Access under Settings>Privacy & Security (I have Ventura OS installed) and I had to create an exception
for /bin/bash app in my Ransomware Shield on my Antivirus program.
Also just checking that you did type in the actual account name of the user and not currentuser.
Posted on 03-10-2023 03:10 AM
I had given full disk access to the Terminal (I guess that is the native bash application) and set the shell option rmstarsilent (to suppress the y/n prompt - though I guess this is not necessary when the script is run through Jamf), but it just doesn't seem to work. I am not running an antivirus program or anything else that I would suspect could prevent access to the files.
I have tried running the script at login, at logout, on a schedule, and as at one time script. Every time Jamf reports the script was run with no exit code but nothing happens.
If I just type “rm -Rf /Users/accountname/Desktop/*” into the Terminal, it works (after setopt rmstartsilent - otherwise I have to type y to delete the files/folders).
And yes, I did type the actual account name 😊
Posted on 03-10-2023 03:21 AM
Try reinstalling your Scripting module that is installed under organisation>settings, this shoud re-install the Jamf School Scripting daemon and the generated certificate on the Macs. Perhaps there is an issue there?
Posted on 03-13-2023 05:56 AM
Ok, I removed the scripting module and installed it again, but the result is still the same: Jamf logs another run of the script, and the time of execution with the exit code "No error" - but the files on the desktop aren't touched.
I reinstalled the iMac I'm using to test, just to see if this would change anything, but it didn't.
03-13-2023 06:41 AM - edited 03-13-2023 06:42 AM
Hmm strange, just as a test, try altering your script somewhere along these lines and set it to run at login:
#!/bin/sh
rm -Rf /Users/accountname/Desktop/*
Failing that, then I think maybe log a support ticket.
Posted on 03-13-2023 07:52 AM
I just tested on one of my newer Macs and came across the same issue, it reports as if it has run but doesn't actually delete the files on the desktop. Think maybe it is an issue with login and logout hooks on newer Mac OS, you may need to set something up like this instead:
Posted on 03-14-2023 05:43 AM
This is getting a bit strange... I can't get it to work like that either. "sudo defaults write com.apple.loginwindow /Users/Shared/scriptToRun.sh" seems to executes without any errors but the script isn't being run. Or it is being run and someting is preventing it from deleting the files.
I tested that the script works as a login item, which it does, but this is not really what I want.
I'll try fidling more with it, and eventually start a ticket with Jamf.
Posted on 03-13-2023 08:06 AM
I tried with #! /bin/sh, /bin/bash and /bin/zsh, but nothing changes.
I agree that it might be time to submit a ticket.
Posted on 03-09-2023 01:03 PM
Depending on which version of macOS you are using, Logout hook no longer works
The Login hook still does, so you can do it at that time, or run the command daily on Recurring Check-in
Posted on 03-10-2023 03:22 AM
I am on Monterey 12.6.3.
I tried running the script on both login, logout, on a schedule and as a ‘just once’ script, and whatever I choose I see the execution counter going up, and the ‘executed at’ time change.
It seems the Script is being run, but something is preventing it from working.
Posted on 03-10-2023 07:38 AM
try this
rm -rvf /Users/<User>/Desktop/*.*
-r = recursive
-v = verbose ( will show you what is deleted )
-f = force
Posted on 03-13-2023 05:59 AM
I changed the script to include *.* and -v, but I still get the same result. The script runs according to Jamf, but the files remain on the desktop.
If I just run the scriptline in Terminal on the machine it works.
Posted on 03-13-2023 06:53 AM
What is / was the output of the script
Posted on 03-13-2023 08:13 AM
When it runs through Jamf, there is no output.
If I make it into a .command file and runs it I get this:
Last login: Mon Mar 13 15:57:24 on ttys000
/Users/user/Documents/ClearUSerFiles.command ; exit;
user@Test-iMac ~ % /Users/user/Documents/ClearUSerFiles.command ; exit;
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
Not really usefull and no files are deleted.
If I open a terminal and run the script from inside the terminal there is no output at all, but the script works. If I specify /Users/user/Desktop/*.* only files are deleted, but /Users/user/Desktop/* will delete everything.
Posted on 03-13-2023 08:23 AM
You need to make the file executable: https://support.apple.com/en-za/guide/terminal/apdd100908f-06b3-4e63-8a87-32e71241bab4/mac
Posted on 03-14-2023 05:32 AM
Following the guide in the link the script runs fine when executed and both files and folders are deleted.
Posted on 03-14-2023 12:38 PM
How about running the executable file on the mac as a startup item using a profile?
Posted on 03-14-2023 12:49 PM
I see from a previous post that this isn’t what you want though. Time to log a ticket with Support, your reseller may be able to either help you or will escalate your issue to someone who does.
03-13-2023 06:40 AM - edited 03-13-2023 06:53 AM
It works if I make it as an Applescript:
#!/usr/bin/osascript
tell application "Finder"
delete every item of folder "Apple HD:Users:user:Desktop"
empty the trash
end tell
But only as "Just once" or on a schedule.
This is however not a solution.