Need help with 'simple' compress and move new file

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

Moderator: Mr_Noodle

Hi there,

I already tried different things with Hazel, but one of my main usage for me does not work until now. I want to compress certain files and move them to a different directory. Sounds simple? Well I thought it was, but it isn't or I am not seeing things through ;)

I have a folder, lets call it 'Test'. Underneath Test we have several folders called 1,2,3,4 and 5. I am watching the folder Test and set up a rule to execute a shell script that compresses a file if it was added to one of those five folders today. What happens now is that Hazel matches the file in folder 5, but does not compress only that file but also tries to compress the whole folder 5. How can I tell Hazel that it should process only the matched file?

Also I get the following error with my script...it runs fine running manually from Terminal.app though.

Code: Select all
2012-08-25 21:54:34.355 hazelworker[14960] [Error] Shell script failed: Error processing shell script on file /Test/5.
2012-08-25 21:54:34.355 hazelworker[14960] Shellscript exited with non-successful status code: 1


Anybody knows a way around this? Help would be much appreciated!
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

Can't tell anything without the script... please post.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

/Applications/BetterZip.app/Contents/Resources/7z a -mx0 -mhe -pTEST Latest.7z $1


That is the script that is beeing included in Hazel.
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

Put quotes around your $1 and it will likely work.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Okay. I'll try that. But the more important thing is my other problem with the whole folder being matched and not just the file being added...
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

What is your rule?

Do you exclude folders from being matched like this:

Code: Select all
if (all) of the following conditions are met for the (file or folder)
    kind IS NOT folder
    ....

Do the following:
    ....
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

I'll actually match folder or sub-folder, because the newly added files are within a subfolder of /Test/...

Code: Select all
if (all) of the following conditions are met for (any of its sub-file or folders)
    kind IS NOT folder
    date addes is today
    name starts with SOMETHING
    ....

Do the following:
   run shell script (the one from above)
    ....
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

Your method will perform the way you describe. When you match (to subfolder), the file that is being processed is not the content of the subfolder, rather it is the parent folder that contains the matching file.

Example:

/Test/1/SOMETHINGMyNewFile.txt

With your rule:
Code: Select all
if (all) of the following conditions are met for (any of its sub-file or folders)
    kind IS NOT folder
    date addes is today
    name starts with SOMETHING


Will perform compression on Folder 1 because you have asked Hazel this: "Every time folder 1 has a new SOMETHING file, compress Folder 1.

What you want to do is have Hazel do this: "Every time folder 1,2,3,... has a new SOMETHING file, compress that file"

I would use a Run Rules on Folder Contents setup for this and keep your rules in check by using subfolder depth conditions. There are dozens of examples of how to do this on the forum.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Or, in the alternative, if you only have five folders, just make five simple rules for five monitor folders.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Hey, almost there! Run on folder contents compresses ALL the folder contents...now I am only looking for a way to compress just the one file that was added today...
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

Make sure that your rules are now "file or folder being matched" too.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

If I change to that, no files are being matched anymore...but that should be the case, since my newly added files are in the subfolders 1,2,3,etc...
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

... and when you do add a file? does it work?
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

No, with "file or folder being matched" nothing gets matched, because there is no file being added right next to the folders, just inside...I'll try some different stuff with nesting tomorrow. Thanks for your help m8!
jlepthien
 
Posts: 11
Joined: Mon Aug 27, 2012 12:31 pm

I'm not sure I understand how you've written these rules. I'll do a test folder and attach some rules in about 15 minutes.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Next

Return to Support