Delete Backup of Pages docs

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Delete Backup of Pages docs Fri Mar 16, 2012 3:38 pm • by ladyfractal
Greetings all;

I'm trying to create a set of rules that will delete the backup of Pages docs that are created automatically. After some frustration, I managed to get it to work by creating a rule that simply fires off at a particular time and calls a shell script that does the following:

find ~/Documents/ -name "Backup of *.pages" -print0 | xargs -0 -I {} rm -rf {}

Which simply does a find on all files with Backup of <something>.pages and then does an rm -rf. I set that to fire off based on a schedule and that actually does accomplish what I'm after.

However, this was the solution I came up with after I couldn't get Hazel to find files. Here are the conditions I used:

Name Contains backup of
Kind Is Pages Document
Date Modified Is Not In The Last 1 Hour

As a test, I just had it apply a blue label to the files but when I test it no results show up. I know I'm missing something subtle but I'm not sure what it is.

The shell script solution works and it is what I'm going to use because it is simple and fast but the geek girl in me just can't let it go that I'm not able to create the correct set of rules. Can anyone spot what I'm doing wrong trying to find these files using Hazel's internal criteria? Like I said, I have a solution that is elegant but I really want to be able to use Hazel to exclude one particular directory that is a child of ~/Documents but I need the criteria above to work in order for that to happen.

Thanks for your help.
ladyfractal
 
Posts: 5
Joined: Fri Mar 16, 2012 3:25 pm

Re: Delete Backup of Pages docs Fri Mar 16, 2012 3:52 pm • by Mr_Noodle
Can you post the whole condition including the heading? I'm guessing you are setting it to match any or all subfiles which is probably not right. Also, see the article at the top about subfolders.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Delete Backup of Pages docs Fri Mar 16, 2012 5:50 pm • by ladyfractal
Mr_Noodle wrote:Can you post the whole condition including the heading? I'm guessing you are setting it to match any or all subfiles which is probably not right. Also, see the article at the top about subfolders.


Sure.

Name: Remove backup of Pages docs

Header: If ALL of the conditions are met In Any sub-file or folder
Condition 1: Kind Is Pages Publication
Condition 2: Name Contains Backup of
Condition 3: Extension is pages

then

Set Label to Blue (Would eventually replace this with something more useful)
ladyfractal
 
Posts: 5
Joined: Fri Mar 16, 2012 3:25 pm

Re: Delete Backup of Pages docs Fri Mar 16, 2012 6:06 pm • by Mr_Noodle
The key thing with setting the targets of conditions to subfiles or the enclosing folder is that it does not affect what file or folder the actions execute on. The point of this is so you can do actions on a file based on conditions of its subfiles or its parents. For example, color a folder blue if it contains any new files.

I'm guessing what you want to do is actually have Hazel scour all the subfolders for files matching and act on each of those files. In that case, see the article at the top of this forum about going into subfolders.

One way to think about it is the "Run rules on folder contents" is like the part of the 'find' command where it goes through the whole file hierarchy. In a separate rule, the conditions (adjusted to operate on the current file, not subfiles) would be the globbing part to match against the files you want to operate on and the actions in this separate rule is the 'xargs' part that it executes.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Delete Backup of Pages docs Fri Mar 16, 2012 6:23 pm • by sjk
ladyfractal wrote:find ~/Documents/ -name "Backup of *.pages" -print0 | xargs -0 -I {} rm -rf {}

Is it just me or do the zeros look like lowercase 'o's when displayed with the noodle3 forum style? They do look like zeros in this reply text box, though.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Delete Backup of Pages docs Fri Mar 16, 2012 6:35 pm • by ladyfractal
sjk wrote:
ladyfractal wrote:find ~/Documents/ -name "Backup of *.pages" -print0 | xargs -0 -I {} rm -rf {}

Is it just me or do the zeros look like lowercase 'o's when displayed with the noodle3 forum style? They do look like zeros in this reply text box, though.


Yeah, they do look like the letter and not the number.
ladyfractal
 
Posts: 5
Joined: Fri Mar 16, 2012 3:25 pm

Re: Delete Backup of Pages docs Fri Mar 16, 2012 6:47 pm • by Mr_Noodle
It might be better to stick stuff like that within code tags.

BTW, did my response help?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Delete Backup of Pages docs Fri Mar 16, 2012 7:19 pm • by ladyfractal
Mr_Noodle wrote:It might be better to stick stuff like that within code tags.

BTW, did my response help?


Yes, it did actually! Thank you very much. I was trying to get Hazel to skip a directory where I don't want the backup files to be deleted because I couldn't make my find | grep | xargs constructions to work correctly. However, I figured out how to make the find command do what I want it to do so I'm just going to have Hazel fire the script off at a given time (which is actually closer to what I really want to happen is just to clean those out once a month). That said, there's some other playing around with Hazel that I want to do (I've chronically underutilized it since I bought it) now that I've gotten a slightly better handle on what I'm doing.

Cheers
Aj
ladyfractal
 
Posts: 5
Joined: Fri Mar 16, 2012 3:25 pm

Re: Delete Backup of Pages docs Mon Mar 19, 2012 12:29 pm • by Mr_Noodle
In the rule to match folders and tell Hazel to descend into it, you can add additional conditions to exclude certain folders from being descended into. I'd suggest playing with that a bit.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support