Delete All Files in Desktop and Downloads

AHSitguy
New Contributor III

Hi,
I'm new to scripting and I'm trying to delete all files and folders within the Desktop folder and the Downloads folder without actually deleting the Desktop folder and Download folder themselves. I've tried using rm -rf /users/username/desktop/* , but it prompts for confirmation and then doesn't execute when trying to deploy through Jamf. Does anyone know how to do this? I want the trigger for the policy to be "at logout".

1 ACCEPTED SOLUTION

AHSitguy
New Contributor III

Using @PaulHazelden's terminal command with a trigger of "Startup" works. I couldn't get it to work at loginlogout though.

View solution in original post

4 REPLIES 4

PaulHazelden
Contributor III

Commands are case sensitive.

rm -Rf /Users/<username>/Desktop/*

Is what I would use. Deleting just the files should be available to the User, but root can do it too. How is your script being executed? Direct out of Jamf or as a local script. From Jamf it will be running as root. As a local script it could be running as the User.
I am guessing you have a way of finding the username, and adding it to the script?
For Log out I would add it as a script, and then add that to a policy, and set the policy to run at logout.

AHSitguy
New Contributor III

@PaulHazelden I'm using the execute command function within Files and Processes in a Jamf Policy.

AHSitguy
New Contributor III

@PaulHazelden I tried your code and it doesn't come up with any errors in Jamf, but it also doesn't work on the Mac. When I run that code in terminal, it prompts for confirmation. How can I enter a Y or yes in the code so that it confirms the deletion?

AHSitguy
New Contributor III

Using @PaulHazelden's terminal command with a trigger of "Startup" works. I couldn't get it to work at loginlogout though.

View solution in original post