How to Get a Rule Sequence to Work?

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

Moderator: Mr_Noodle

How to Get a Rule Sequence to Work? Mon Jun 10, 2013 10:15 pm • by rafarc21
Hello guys, after searching and trying a lot I decided to post.

Here's what I wanna do:

Rip a CD into 4 formats, sort the files into subfolders, rename properly and create+open torrents of each format's folder.

Here's what I'm doing:

The Ripping goes manually because I often need to fix tags.

Step 1 - sorting into subfolders

Once I have all 4 formats files in a folder with the album's name, I can properly Set them into subfolders using these self-explanatory rules (download link: http://cl.ly/2t360N132Z3i):

Image

That works great.

Step 2 - Renaming

Now I need to remove the format tag that goes into each file name (eg "1 - song a(320 CBR).mp3"). I need to remove "(320 CBR)". Heres is my problem. If I add and check the "Renaming" rule after the "Set to [Format] Subfolder" rules and run it all together, it dosent work. Even when putting another "Go to Subfolder" rule in between. BUT, If I run the first 5 rules (of step 1) and then uncheck them and check and run the last 2 rules of step 2 (Go to Subfolder + Rename), it works. So, bottom line, they work separately but do not in sequence.

Question: How to make rules properly run in sequence?

Thanks! :D
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Tue Jun 11, 2013 10:45 am • by Mr_Noodle
Only one rule can match (and be subsequently run) on a file. If you want to perform a renaming action after sorting, you should add the action to the same rule. I suggest giving that a shot.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: How to Get a Rule Sequence to Work? Tue Jun 11, 2013 1:24 pm • by rafarc21
Thanks Mr_Noodle!! That works! awesome.

But now, to create torrents with the folders, I'd have to match again, right?

I can do that by running a 'Got to Subfolder - Run Rules on Folder Contents - Run Create Torrent Script " from the enclosing folder. But I dont think thats the optimal way, is it ?

Any ideas ?

Heres the script to Create Torrent with Transmission CLI:
http://cl.ly/0q0M0z2y3L3C
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Wed Jun 12, 2013 2:47 pm • by Mr_Noodle
You are trying to create a torrent from the containing folders, right? Not sure if I fully understand the exact workflow here but you might need to do it in separate phases where you set a color label when done with one phase and then match against that label to do the next phase.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: How to Get a Rule Sequence to Work? Thu Jun 13, 2013 5:49 pm • by rafarc21
Ok, sorry!

I want to create torrents of the "[format] subfolder"s that were created in the first step. They are the ones in blue, see:

Image
*I set the blue label manually

With my current rule setup (as in my first post) running on the folder Organizing, the enclosing (Organizing) and the subfolder (Otto - Condom Black (2001)) are being set to red color label by the first rule.

So, what I get from running Hazel into this:

Image

Is this:

Image

So, I understand your advice, but where should I place these next 3 rules (set "[format] subfolder" label red + matching + create torrents)?


Thanks!
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Fri Jun 14, 2013 12:34 pm • by Mr_Noodle
How do you know when the format folders are ready to be processed? Your rules keep adding folders to it but how do you (or more specifically, how should Hazel know) when that part is done and that you can process the whole folder?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: How to Get a Rule Sequence to Work? Sun Jun 16, 2013 1:43 pm • by rafarc21
Hazel can match the [Format] Subfolders with the rule:

- kind is folder > name ends with "]"
- A Spotlight Comment on the [Format] subfolders added on the naming pattern of the sort into subfolders rule (not sure if its necessary)

Now question is: where to place this Phase 2 Matching Rule?
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Mon Jun 17, 2013 10:53 am • by Mr_Noodle
Put it before the other ones. It has extra conditions which won't match for an unprocessed file so it should work though it also depends on the specifics of your rules. If you still can't get it right, post your full rule set.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: How to Get a Rule Sequence to Work? Sat Jun 22, 2013 4:13 pm • by rafarc21
it works!! \o/\o/\o/ Thanks sir!

Now that I can run the script on the right folders, I getting an 127 shell script error. The script works perfectly running in the terminal but it returns error 127 running on hazel.

Here is my log: http://cl.ly/2i1S3N0S0X2A

I'm pretty sure its because of this

http://www.noodlesoft.com/forums/viewtopic.php?f=4&t=1342

because my script needs access to ~/.bash_profile .

So, question is: How do I write the full pathname so that Hazel can access .bash_profile?

Detailed info on the script:
http://blog.kejsarmakten.se/all/software/2011/10/18/sending-file-as-torrent.html

Current Hazel rules:
http://cl.ly/3h181M172p2N
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Mon Jun 24, 2013 3:56 am • by xor2000
Mr_Noodle wrote:Only one rule can match (and be subsequently run) on a file. If you want to perform a renaming action after sorting, you should add the action to the same rule. I suggest giving that a shot.


Sorry for chiming in, but I think this request shows that Hazel-Rules get unnecessarily complex just because you can not continue matching after one rule has matched. This leads to very complex and hard to maintain rules.

Simple example: I want to

- do action A for files matching condition a
- do action B for files matching condition b
- do action C for files matching condition c

Instead of having 3 simple rules, each handled in sequence, in Hazel I need to come up with the following 7 rules:

- do action A if a matches, but not b and not c
- do action B if b matches, but not a and not c
- do action C if c matches, but not a and not b
- do action A and B if a and b matches, but not c
- do action B and C if b and c matches, but not a
- do action A and C if a and c matches, but not b
- do action A, B and C if a, b, and c matches

What a mess!

And now suppose you need to change action A or condition b: Happy rule editing (you need to change each of them)!

Or add another action D on files matching condition d: the number of required rules will grow, as will their complexity.

Please, Mr. Noodle, consider fixing this by adding a "Continue running rules" action.

Related post:
viewtopic.php?f=4&t=1163&p=4997#p4997
xor2000
 
Posts: 13
Joined: Mon Oct 17, 2011 4:54 pm

Re: How to Get a Rule Sequence to Work? Mon Jun 24, 2013 1:19 pm • by Mr_Noodle
It's on the list but it does complicate many other things. I can't say when it will be implemented but keep in mind it's not just a trivial thing to add. There are a few behaviors where it's not clear how to deal with it.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: How to Get a Rule Sequence to Work? Mon Jun 24, 2013 9:45 pm • by rafarc21
Thanks for the input xor2000 ! Actually I think besides placing the 2nd matching rule on top of the first action rules, what helped solving my problem was to leave Hazel running, instead of just pressing Run Rules Now. That way, it keeps trying to match the 2nd matching rule and only does so after the action rules work.

Still, it would be great to have that feature empowered for more complex cases in which the above described might not work.

--------------------------------------------
Regarding the current issue, Mr_Noodle, should I create another Topic for the question below?
rafarc21 wrote:So, question is: How do I write the full pathname so that Hazel can access .bash_profile?


Thanks !
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Tue Jun 25, 2013 12:42 am • by sjk
Disclaimer: Without knowing exactly which "full pathname" your question refers to I'll try answering anyway …

rafarc21 wrote:So, question is: How do I write the full pathname so that Hazel can access .bash_profile?

Possibly by invoking the bash shell with the "-l" (dash-ell) or "--login" option. From the bash man page:

-l Make bash act as if it had been invoked as a login shell (see INVOCATION below).
--login Equivalent to -l.

A shebang line would be:

Code: Select all
#!/bin/bash -l
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: How to Get a Rule Sequence to Work? Tue Jun 25, 2013 7:58 pm • by rafarc21
Hi sjk, many thanks for your help.
sjk wrote:Disclaimer: Without knowing exactly which "full pathname" your question refers to I'll try answering anyway …

I'm referring to what Mr_Noodle pointed out as a solution on this topic:

http://www.noodlesoft.com/forums/viewtopic.php?f=4&t=1342

The same solution that worked for the guy above is what I need. But I have near-zero knowledge of coding to know straight forward what "specify the full path of the command" means.

I tried what you suggested, but Im not sure if did it right. The many ways I tried resulted in error code 127 (command not found).

I also tried this:
Image
and it got me error code 900, which I couldn't find the meaning. Heres a log http://cl.ly/2L3h403M2m36

I see your solution makes perfect sense, I just don't know how to apply it. Can you elaborate a bit more please?

If you can tell me exactly what goes into the Shell field and what add to the script field, I'd be thrilled!

My script consist only of:

Code: Select all
createtorrent $1


The core of the script in in the .bash_profile , as you can see here:
http://blog.kejsarmakten.se/all/software/2011/10/18/sending-file-as-torrent.html
rafarc21
 
Posts: 10
Joined: Mon Jun 10, 2013 9:26 pm

Re: How to Get a Rule Sequence to Work? Tue Jun 25, 2013 9:30 pm • by sjk
rafarc21 wrote:But I have near-zero knowledge of coding to know straight forward what "specify the full path of the command" means.

Mr_Noodle was referring to using the full (absolute) pathname for the command within the script, e.g. /usr/local/bin/pdflatex instead of just pdflatex. A web search for "full pathname unix" will have results with more explanation of what that is, e.g. in:

UNIX Concepts

If you can tell me exactly what goes into the Shell field and what add to the script field, I'd be thrilled!

Try changing the Shell: field to /usr/bin/bash -l and removing #!/bin/.bash_profile -l from the embedded script text. The intention is to force bash to read .bash_profile by invoking it (bash) with the "-l" option. I haven't tested if the Shell: field for an embedded script processes any options.

If that doesn't work you could try converting the createtorrent function into an embedded script directly in Hazel, removing the external dependency on .bash_profile (which is possibly preferable anyway). Something like this (with minor adjustments):

Code: Select all
FILENAME=$1
mktor -p $FILENAME udp://tracker.openbittorrent.com:80/announce
open $FILENAME.torrent
echo "tell application \"Mail\"
 activate
  set MyEmail to make new outgoing message with properties {visible:true, content:\"Torrent file transfer    \"}
 tell MyEmail
   make new attachment with properties {file name:((\"$FILENAME.torrent\" as POSIX file) as alias)}
 end tell
end tell
" | osascript

The escaping/quoting of some of that might need fixing. A full pathname may be necessary for at least the mktor command in that script, e.g. /usr/local/bin/mktor. And the open $FILENAME.torrent line can be removed if you don't want the torrent client opening the file every time Hazel runs this script.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Next

Return to Support