script application set up question
Hi,
When I add script as below, after run , it will show message:some files could not be moved to the trash,
How to ignore it and keep the script to run complete? And how to add to assigned folder?Thanks.
You can make a difference in the Apple Support Community!
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.
Hi,
When I add script as below, after run , it will show message:some files could not be moved to the trash,
How to ignore it and keep the script to run complete? And how to add to assigned folder?Thanks.
While the modern approach is to use a launch daemon with a schedule, the old way of using cron is often simpler, especially with the changes made to launchd over the past few OS releases.
If you make this an app, you can modify /etc/crontab (requires admin rights) and create an entry to trigger the tool on a regular schedule. For example, if you want a script.sh to execute under the user context of username (meaning your user account), at 20:45 (8:45 p.m.), every day, every day of the week, and every day of the month, you would use a line like this. First column is minutes, second is hours in 24 hour time.
45 20 * * * username /Library/username/path/to/script.sh
Search for cron or crontab examples and you will find lots of examples.
If you want to do it the "modern" way, start here with Apple's dev docs.
Either path can get you to scheduling a process to run at repeated intervals.
Try removing the -o as I believe that is an or conditional. Thus, the command is looking for files (-type f) with a -ctime of +1d OR anything with an -mtime of +1d. If the folder has an -mtime of +1d than it is included because of the -o.
I likely should ask some questions at this point.
• Describe the workflow you are trying to achieve. I know you are trying to clear files from a folder based on matching criteria. That I get. But when do you want this to run? Is it running all the time (watched folder)? Is it running once a day (cron or launch daemon)? Every hour? And how do you plan to trigger this? Are you double clicking something? Is it running automatically in the background?
Hi Strontium90
I try to find solution which can automatically delete assigned folder, so I study about automate.
How can I keep original folder not to be deleted? For example, if the path is /users/anderson/downloads/mergemodules/, the folder mergemodules will be also deleted, but I only would like to delete files in it. Thanks.
I think the issue is the -iname '*.*' as I am going to speculate it is trying to delete the hidden . or .. special files inside all directories. For example, if I break this down and run the following command on a folder:
find . -iname '*.*'
The result is:
.
./.DS_Store
./bff02d99-1309-4215-a32a-829ccff47b84_Part003.zip
./bff02d99-1309-4215-a32a-829ccff47b84_Part002.zip
./bff02d99-1309-4215-a32a-829ccff47b84_Part001.zip
./afile.txt
Note that . is included at the top of the results. You cannot move that item to the trash. This is the cause of your error.
You should modify or remove the -iname directive. You are already searching for creative time more than 1 day and modify time of more than 1 day. Why include a name wildcard when all files that match the time criteria will be included regardless of name?
You might consider focusing just on files as this will ignore directories and specials. If you are only trying to remove files, then perhaps a:
find /your/path -type f -ctime +1d -o -mtime +1d
If you are already using find, why not just append a -delete the end? Then you can remove the "Move Finder Items to Trash." Note, if you use -delete, then the files are gone. If you are looking for the safety net of the Trash, then continue to use the second tile in your automation to move to trash for later deletion.
Make sure you test these recommendation on sample data. I do not know the entirety of your workflow or your intended goals. I am providing a suggestion based on what is posted. The command and recommendation I provide above can result in file deletion. Run incorrectly, this could result in data loss. Test before implementing. Trust, but verify.
You can save a shell script as a .sh file and then chmod 755 it. But if you are using a shell script, you will need to use osascript within it to call the AppleScript part of the script. If you want to stay with Automator, then save it as an App as that will be double-clickable to run.
Thanks @Strontium90
There is some condition, when I edit to save sh file, it show error message. But it can run in automate.
Hi Strontium90
Thanks, I original think it will trigger it automatically, if I would like to trigger it everyday one time, how to do it? Thanks.
script application set up question