Cleanup Script for macOS
I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to build a basic shell script that will delete desktop files and folders older than a set number of days, and empty the trash for all users. This is what I have come up with so far:
# Delete desktop files and folders older than 30 days
sudo find /Users/*/Desktop/ -type d -or -type f ! -name '.DS_Store' !
-name '.localized' -mtime +30 -exec rm -rf '{}' +;
# Empty Trash for all users
rm -rf /Users/*/.Trash/*
I understand the potential danger of getting the syntax wrong on a script like this. I have tested running this on just my account (replaced * with my user), and while it seems to work for files, the old folders on my desktop are not getting deleted. I'm wondering what I'm getting wrong, if there is perhaps a better way to execute this, and maybe add some polish with a confirmation dialog (ie. "WARNING: This will permanently delete all desktop files and folders older than 30 days, and empty the trash for all users! OK to proceed?").
bash shell-script osx
add a comment |
I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to build a basic shell script that will delete desktop files and folders older than a set number of days, and empty the trash for all users. This is what I have come up with so far:
# Delete desktop files and folders older than 30 days
sudo find /Users/*/Desktop/ -type d -or -type f ! -name '.DS_Store' !
-name '.localized' -mtime +30 -exec rm -rf '{}' +;
# Empty Trash for all users
rm -rf /Users/*/.Trash/*
I understand the potential danger of getting the syntax wrong on a script like this. I have tested running this on just my account (replaced * with my user), and while it seems to work for files, the old folders on my desktop are not getting deleted. I'm wondering what I'm getting wrong, if there is perhaps a better way to execute this, and maybe add some polish with a confirmation dialog (ie. "WARNING: This will permanently delete all desktop files and folders older than 30 days, and empty the trash for all users! OK to proceed?").
bash shell-script osx
1
Users will love this. I have seen users leaving all the kind of files in their desktops. A colleague of mine had a case where a sweet lady told him she though the bin/trashcan picture was meant "to be a place to store my work files". Have you any specific question why you think it might be wrong? Validating everything every step of the way seems strange (do more testing if unsure, find volunteers)
– Rui F Ribeiro
Jan 16 at 19:38
1
Related:sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
. This sets the thirty-day automatic trash removal option for $username.
– Christopher
Jan 16 at 19:46
@Christopher That one is good enough to make it an answer.
– Rui F Ribeiro
Jan 16 at 19:50
1
A caveat exists on the dialog portion for SIP-enabled Mojave. To get the dialog portion working, each user requires an entry inSystem Preferences
>Security & Privacy
>Privacy
>Automation
to give a terminal access toSystem Events.app
, which displays the dialog. So... which version of the OS?
– Christopher
Jan 16 at 20:51
Thanks for the heads-up. Currently we're on a mix of Sierra and High Sierra, no Mojave. The dialog is more of a "nice to have", I'm mainly trying to figure out why desktop folders older than 30 days are not being deleted using the script in it's current state.
– animism
Jan 16 at 22:06
add a comment |
I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to build a basic shell script that will delete desktop files and folders older than a set number of days, and empty the trash for all users. This is what I have come up with so far:
# Delete desktop files and folders older than 30 days
sudo find /Users/*/Desktop/ -type d -or -type f ! -name '.DS_Store' !
-name '.localized' -mtime +30 -exec rm -rf '{}' +;
# Empty Trash for all users
rm -rf /Users/*/.Trash/*
I understand the potential danger of getting the syntax wrong on a script like this. I have tested running this on just my account (replaced * with my user), and while it seems to work for files, the old folders on my desktop are not getting deleted. I'm wondering what I'm getting wrong, if there is perhaps a better way to execute this, and maybe add some polish with a confirmation dialog (ie. "WARNING: This will permanently delete all desktop files and folders older than 30 days, and empty the trash for all users! OK to proceed?").
bash shell-script osx
I have a bunch of shared Mac workstations with dozens of users. These users constantly leave large files on their desktop and in the trash, which eventually fills up the local hard drive. I want to build a basic shell script that will delete desktop files and folders older than a set number of days, and empty the trash for all users. This is what I have come up with so far:
# Delete desktop files and folders older than 30 days
sudo find /Users/*/Desktop/ -type d -or -type f ! -name '.DS_Store' !
-name '.localized' -mtime +30 -exec rm -rf '{}' +;
# Empty Trash for all users
rm -rf /Users/*/.Trash/*
I understand the potential danger of getting the syntax wrong on a script like this. I have tested running this on just my account (replaced * with my user), and while it seems to work for files, the old folders on my desktop are not getting deleted. I'm wondering what I'm getting wrong, if there is perhaps a better way to execute this, and maybe add some polish with a confirmation dialog (ie. "WARNING: This will permanently delete all desktop files and folders older than 30 days, and empty the trash for all users! OK to proceed?").
bash shell-script osx
bash shell-script osx
edited Jan 16 at 19:36
Rui F Ribeiro
39.6k1479132
39.6k1479132
asked Jan 16 at 19:30
animismanimism
133
133
1
Users will love this. I have seen users leaving all the kind of files in their desktops. A colleague of mine had a case where a sweet lady told him she though the bin/trashcan picture was meant "to be a place to store my work files". Have you any specific question why you think it might be wrong? Validating everything every step of the way seems strange (do more testing if unsure, find volunteers)
– Rui F Ribeiro
Jan 16 at 19:38
1
Related:sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
. This sets the thirty-day automatic trash removal option for $username.
– Christopher
Jan 16 at 19:46
@Christopher That one is good enough to make it an answer.
– Rui F Ribeiro
Jan 16 at 19:50
1
A caveat exists on the dialog portion for SIP-enabled Mojave. To get the dialog portion working, each user requires an entry inSystem Preferences
>Security & Privacy
>Privacy
>Automation
to give a terminal access toSystem Events.app
, which displays the dialog. So... which version of the OS?
– Christopher
Jan 16 at 20:51
Thanks for the heads-up. Currently we're on a mix of Sierra and High Sierra, no Mojave. The dialog is more of a "nice to have", I'm mainly trying to figure out why desktop folders older than 30 days are not being deleted using the script in it's current state.
– animism
Jan 16 at 22:06
add a comment |
1
Users will love this. I have seen users leaving all the kind of files in their desktops. A colleague of mine had a case where a sweet lady told him she though the bin/trashcan picture was meant "to be a place to store my work files". Have you any specific question why you think it might be wrong? Validating everything every step of the way seems strange (do more testing if unsure, find volunteers)
– Rui F Ribeiro
Jan 16 at 19:38
1
Related:sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
. This sets the thirty-day automatic trash removal option for $username.
– Christopher
Jan 16 at 19:46
@Christopher That one is good enough to make it an answer.
– Rui F Ribeiro
Jan 16 at 19:50
1
A caveat exists on the dialog portion for SIP-enabled Mojave. To get the dialog portion working, each user requires an entry inSystem Preferences
>Security & Privacy
>Privacy
>Automation
to give a terminal access toSystem Events.app
, which displays the dialog. So... which version of the OS?
– Christopher
Jan 16 at 20:51
Thanks for the heads-up. Currently we're on a mix of Sierra and High Sierra, no Mojave. The dialog is more of a "nice to have", I'm mainly trying to figure out why desktop folders older than 30 days are not being deleted using the script in it's current state.
– animism
Jan 16 at 22:06
1
1
Users will love this. I have seen users leaving all the kind of files in their desktops. A colleague of mine had a case where a sweet lady told him she though the bin/trashcan picture was meant "to be a place to store my work files". Have you any specific question why you think it might be wrong? Validating everything every step of the way seems strange (do more testing if unsure, find volunteers)
– Rui F Ribeiro
Jan 16 at 19:38
Users will love this. I have seen users leaving all the kind of files in their desktops. A colleague of mine had a case where a sweet lady told him she though the bin/trashcan picture was meant "to be a place to store my work files". Have you any specific question why you think it might be wrong? Validating everything every step of the way seems strange (do more testing if unsure, find volunteers)
– Rui F Ribeiro
Jan 16 at 19:38
1
1
Related:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
. This sets the thirty-day automatic trash removal option for $username.– Christopher
Jan 16 at 19:46
Related:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
. This sets the thirty-day automatic trash removal option for $username.– Christopher
Jan 16 at 19:46
@Christopher That one is good enough to make it an answer.
– Rui F Ribeiro
Jan 16 at 19:50
@Christopher That one is good enough to make it an answer.
– Rui F Ribeiro
Jan 16 at 19:50
1
1
A caveat exists on the dialog portion for SIP-enabled Mojave. To get the dialog portion working, each user requires an entry in
System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. So... which version of the OS?– Christopher
Jan 16 at 20:51
A caveat exists on the dialog portion for SIP-enabled Mojave. To get the dialog portion working, each user requires an entry in
System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. So... which version of the OS?– Christopher
Jan 16 at 20:51
Thanks for the heads-up. Currently we're on a mix of Sierra and High Sierra, no Mojave. The dialog is more of a "nice to have", I'm mainly trying to figure out why desktop folders older than 30 days are not being deleted using the script in it's current state.
– animism
Jan 16 at 22:06
Thanks for the heads-up. Currently we're on a mix of Sierra and High Sierra, no Mojave. The dialog is more of a "nice to have", I'm mainly trying to figure out why desktop folders older than 30 days are not being deleted using the script in it's current state.
– animism
Jan 16 at 22:06
add a comment |
1 Answer
1
active
oldest
votes
Automatic Trash Removal
To set the thirty-day automatic Trash removal option for $username:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
Presenting a Dialog
Please note that to get the dialog portion working on a SIP-enabled Mojave, each user requires an entry in System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. Here's one using osascript
that looks as follows.
If a user clicks "Yes," then the exit code from the dialog is 0 (zero). One might incorporate knowledge of the dialog's successful exit code with a script, as shown below.
#!/usr/bin/env bash
osascript -e 'tell app "System Events" to display dialog "Hi. I am automated script. May I delete Desktop & Trash files older than 30 days?" buttons {"Yes", "No"} with icon caution' >/dev/null 2>&1
# $? is the exit code of the very last command that was executed (osascript).
#
if [ $? -eq 0 ]; then
# Do something.
echo "You clicked Yes."
fi
Finding Files
Below, finding files of specific types (file and directory) whose names are not .DS_Store
or .localized
and that are 30+ days old. The first line is for a safe test. Swap with the line below it to delete found objects. If an option needs to be specified more than once, use -o
. Be sure to escape () special characters. The whitespace at the beginning and end of the parentheses is also important.
#!/usr/bin/env bash
find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -print
# find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -exec rm -rf '{}' +
Listing Users
#!/usr/bin/env bash
# Getting a list of users, filtering out service accounts, root, daemon, and nobody...
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')
for user in "$users"; do
# Do something.
id "$user"
done
unset users
Obviously there is some interpolation to do in order to stitch these snippets into a working script, but I hope it provides at least a bit more insight. Were it me, I think I might try to keep the script in /usr/local/bin
and then set up a cron job to execute the script monthly.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494910%2fcleanup-script-for-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Automatic Trash Removal
To set the thirty-day automatic Trash removal option for $username:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
Presenting a Dialog
Please note that to get the dialog portion working on a SIP-enabled Mojave, each user requires an entry in System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. Here's one using osascript
that looks as follows.
If a user clicks "Yes," then the exit code from the dialog is 0 (zero). One might incorporate knowledge of the dialog's successful exit code with a script, as shown below.
#!/usr/bin/env bash
osascript -e 'tell app "System Events" to display dialog "Hi. I am automated script. May I delete Desktop & Trash files older than 30 days?" buttons {"Yes", "No"} with icon caution' >/dev/null 2>&1
# $? is the exit code of the very last command that was executed (osascript).
#
if [ $? -eq 0 ]; then
# Do something.
echo "You clicked Yes."
fi
Finding Files
Below, finding files of specific types (file and directory) whose names are not .DS_Store
or .localized
and that are 30+ days old. The first line is for a safe test. Swap with the line below it to delete found objects. If an option needs to be specified more than once, use -o
. Be sure to escape () special characters. The whitespace at the beginning and end of the parentheses is also important.
#!/usr/bin/env bash
find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -print
# find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -exec rm -rf '{}' +
Listing Users
#!/usr/bin/env bash
# Getting a list of users, filtering out service accounts, root, daemon, and nobody...
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')
for user in "$users"; do
# Do something.
id "$user"
done
unset users
Obviously there is some interpolation to do in order to stitch these snippets into a working script, but I hope it provides at least a bit more insight. Were it me, I think I might try to keep the script in /usr/local/bin
and then set up a cron job to execute the script monthly.
add a comment |
Automatic Trash Removal
To set the thirty-day automatic Trash removal option for $username:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
Presenting a Dialog
Please note that to get the dialog portion working on a SIP-enabled Mojave, each user requires an entry in System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. Here's one using osascript
that looks as follows.
If a user clicks "Yes," then the exit code from the dialog is 0 (zero). One might incorporate knowledge of the dialog's successful exit code with a script, as shown below.
#!/usr/bin/env bash
osascript -e 'tell app "System Events" to display dialog "Hi. I am automated script. May I delete Desktop & Trash files older than 30 days?" buttons {"Yes", "No"} with icon caution' >/dev/null 2>&1
# $? is the exit code of the very last command that was executed (osascript).
#
if [ $? -eq 0 ]; then
# Do something.
echo "You clicked Yes."
fi
Finding Files
Below, finding files of specific types (file and directory) whose names are not .DS_Store
or .localized
and that are 30+ days old. The first line is for a safe test. Swap with the line below it to delete found objects. If an option needs to be specified more than once, use -o
. Be sure to escape () special characters. The whitespace at the beginning and end of the parentheses is also important.
#!/usr/bin/env bash
find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -print
# find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -exec rm -rf '{}' +
Listing Users
#!/usr/bin/env bash
# Getting a list of users, filtering out service accounts, root, daemon, and nobody...
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')
for user in "$users"; do
# Do something.
id "$user"
done
unset users
Obviously there is some interpolation to do in order to stitch these snippets into a working script, but I hope it provides at least a bit more insight. Were it me, I think I might try to keep the script in /usr/local/bin
and then set up a cron job to execute the script monthly.
add a comment |
Automatic Trash Removal
To set the thirty-day automatic Trash removal option for $username:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
Presenting a Dialog
Please note that to get the dialog portion working on a SIP-enabled Mojave, each user requires an entry in System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. Here's one using osascript
that looks as follows.
If a user clicks "Yes," then the exit code from the dialog is 0 (zero). One might incorporate knowledge of the dialog's successful exit code with a script, as shown below.
#!/usr/bin/env bash
osascript -e 'tell app "System Events" to display dialog "Hi. I am automated script. May I delete Desktop & Trash files older than 30 days?" buttons {"Yes", "No"} with icon caution' >/dev/null 2>&1
# $? is the exit code of the very last command that was executed (osascript).
#
if [ $? -eq 0 ]; then
# Do something.
echo "You clicked Yes."
fi
Finding Files
Below, finding files of specific types (file and directory) whose names are not .DS_Store
or .localized
and that are 30+ days old. The first line is for a safe test. Swap with the line below it to delete found objects. If an option needs to be specified more than once, use -o
. Be sure to escape () special characters. The whitespace at the beginning and end of the parentheses is also important.
#!/usr/bin/env bash
find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -print
# find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -exec rm -rf '{}' +
Listing Users
#!/usr/bin/env bash
# Getting a list of users, filtering out service accounts, root, daemon, and nobody...
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')
for user in "$users"; do
# Do something.
id "$user"
done
unset users
Obviously there is some interpolation to do in order to stitch these snippets into a working script, but I hope it provides at least a bit more insight. Were it me, I think I might try to keep the script in /usr/local/bin
and then set up a cron job to execute the script monthly.
Automatic Trash Removal
To set the thirty-day automatic Trash removal option for $username:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
Presenting a Dialog
Please note that to get the dialog portion working on a SIP-enabled Mojave, each user requires an entry in System Preferences
> Security & Privacy
> Privacy
> Automation
to give a terminal access to System Events.app
, which displays the dialog. Here's one using osascript
that looks as follows.
If a user clicks "Yes," then the exit code from the dialog is 0 (zero). One might incorporate knowledge of the dialog's successful exit code with a script, as shown below.
#!/usr/bin/env bash
osascript -e 'tell app "System Events" to display dialog "Hi. I am automated script. May I delete Desktop & Trash files older than 30 days?" buttons {"Yes", "No"} with icon caution' >/dev/null 2>&1
# $? is the exit code of the very last command that was executed (osascript).
#
if [ $? -eq 0 ]; then
# Do something.
echo "You clicked Yes."
fi
Finding Files
Below, finding files of specific types (file and directory) whose names are not .DS_Store
or .localized
and that are 30+ days old. The first line is for a safe test. Swap with the line below it to delete found objects. If an option needs to be specified more than once, use -o
. Be sure to escape () special characters. The whitespace at the beginning and end of the parentheses is also important.
#!/usr/bin/env bash
find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -print
# find "$HOME/Desktop" -type f -o -type d -mtime +30 ! ( -name '.DS_Store' -o -name '.localized' ) -exec rm -rf '{}' +
Listing Users
#!/usr/bin/env bash
# Getting a list of users, filtering out service accounts, root, daemon, and nobody...
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')
for user in "$users"; do
# Do something.
id "$user"
done
unset users
Obviously there is some interpolation to do in order to stitch these snippets into a working script, but I hope it provides at least a bit more insight. Were it me, I think I might try to keep the script in /usr/local/bin
and then set up a cron job to execute the script monthly.
edited Jan 17 at 1:03
answered Jan 16 at 23:40
ChristopherChristopher
10.3k33048
10.3k33048
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494910%2fcleanup-script-for-macos%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Users will love this. I have seen users leaving all the kind of files in their desktops. A colleague of mine had a case where a sweet lady told him she though the bin/trashcan picture was meant "to be a place to store my work files". Have you any specific question why you think it might be wrong? Validating everything every step of the way seems strange (do more testing if unsure, find volunteers)
– Rui F Ribeiro
Jan 16 at 19:38
1
Related:
sudo -u $username bash -c 'defaults write com.apple.finder FXRemoveOldTrashItems -bool true'
. This sets the thirty-day automatic trash removal option for $username.– Christopher
Jan 16 at 19:46
@Christopher That one is good enough to make it an answer.
– Rui F Ribeiro
Jan 16 at 19:50
1
A caveat exists on the dialog portion for SIP-enabled Mojave. To get the dialog portion working, each user requires an entry in
System Preferences
>Security & Privacy
>Privacy
>Automation
to give a terminal access toSystem Events.app
, which displays the dialog. So... which version of the OS?– Christopher
Jan 16 at 20:51
Thanks for the heads-up. Currently we're on a mix of Sierra and High Sierra, no Mojave. The dialog is more of a "nice to have", I'm mainly trying to figure out why desktop folders older than 30 days are not being deleted using the script in it's current state.
– animism
Jan 16 at 22:06