Page 1 of 1
Custom tokens between rules

Posted:
Mon Jul 30, 2012 5:36 am
by ilium007
Hi,
I think I already know the answer to this but can I export a custom token from one rule and then use it later within the same set of rules ?
My workflow has a DVD rip hit a folder and then runs a convert rule. I export a token at this point. The completion of the rip results in the next rule based on the presence of a .dvdmedia folder in the watched folder. This then converts, makes am mkv, passes tio iFlicks etc etc. The final step is a separate rule that looks for an .mkv file hitting the same folder, this rule moves the .dvdmedia to the trash signalling the end of the workflow.
I want to gain access to the token I exported originally so I can post a Growl/Prowl notification that the movie has been completed.
Is this possible ? Cheers
Re: Custom tokens between rules

Posted:
Mon Jul 30, 2012 3:04 pm
by Mr_Noodle
No, the tokens are limited to the rule they are defined in.
I'm a but unclear how you set up your rules in this case and at which point exactly you want the notification to happen. Could you elaborate?
Re: Custom tokens between rules

Posted:
Tue Jul 31, 2012 12:36 am
by ilium007
Ok I'll try to explain a bit better !
I have an action that is watching a folder /DVD-rips
This action has 4 rules. The first rule gets the DVD rip that has hit the folder and does some trickery via AppleScript to get a name for the movie. I want to use this name later on in a Growl notification. So I thought I would export it as a custom token.
The rule then goes through the next 3 steps which handbrake encodes, adds iflicks metadata and imports to iTunes. The final step is a move of the DVD rip to an archive folder. It is in the last rule that I want to display a growl alert using the custom token I exported from the first rule.
Does this make it any clearer ? Cheers.
Re: Custom tokens between rules

Posted:
Tue Jul 31, 2012 2:06 pm
by Mr_Noodle
My confusion here is whether you mean actions or rules. A rule can have multiple actions that are performed. I'm not sure where the division lies with your workflow.
If each of those steps is its own rule, is there a reason why you couldn't have them as a bunch of actions within a single rule?
Re: Custom tokens between rules

Posted:
Tue Jul 31, 2012 8:07 pm
by ilium007
I mean rules. I want to export a token from one rule and import to another:

Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 2:17 pm
by Mr_Noodle
What I'm missing is why this is done in separate rules and how it is that you have separate rules and allow the file to match each one in succession.
It might be better if you email support with your rulesets so I can take a look at the whole thing at once.
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 2:39 pm
by a_freyer
First, I share Mr_Noodle's confusion as to why this is in multiple rules.
However, in direct answer to your question, here is what I'd do:
- Code: Select all
Rule 1:
if (all) ...
<whatever>
then
<whatever>
Add spotlight comment [[(custom token•)]]
I add the double brackets enclosing the comment so that we can:
- Code: Select all
Rule 2:
if (all) ...
<whatever>
Spotlight Comments match [[(custom token •)]]
then
<whatever>
Now you have successfully passed your token to subsequent rules.
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 4:47 pm
by ilium007
I certainly didn't mean to cause so much confusion. Please tell me if I am using Hazel incorrectly but this little workflow has been pretty rock solid in processing my downloaded TV shows for over a year now.
These are my rules:

First step:
.mkv hits watched folder
It color lobel isnt Green then run the convertVideo script which kicks off Handbrake
When completed encoding it turns .mkv Green
Convert Video AppleScript:- Code: Select all
on mobile_alert(themessage)
do shell script "perl /Users/xxxxxx/support/scripts/prowl.pl -apikey=xxxxxxx -application=iFlicks -event=\"Movie Processing\" -notification=" & the quoted form of themessage
end mobile_alert
on hazelProcessFile(theFile)
set errorCount to 0
-- set priority to button returned of question
set priority to "High"
with timeout of 1000000 seconds
try
tell application "Finder"
set label index of theFile to 1
--used to extract the name and location of the file
set itemProp to properties of theFile
--where the file is
set sourceFile to quoted form of POSIX path of theFile
--where the compressed file should end up
set destFold to quoted form of POSIX path of (container of itemProp as alias)
--what the name of the file is
--set extension hidden of theFile to true
if extension hidden of theFile then
set itemName to displayed name of theFile
else
set extension hidden of theFile to true
set itemName to displayed name of theFile
set extension hidden of theFile to false
end if
set itemExtension to name extension of theFile
--set itemBody to name body of theFile
--display dialog itemExtension
set tmpFile to "/Volumes/HDD2/" & itemName & "_handbrake_encode.tmp"
--display dialog tmpFile
try
--Convert Movie
if priority is equal to "Low" then
set ConvertMovieCmd to "nice /Applications/HandBrakeCLI -i " & sourceFile & " -o " & quoted form of (tmpFile) & " --preset=\"AppleTV 2\" --main-feature;"
else
set ConvertMovieCmd to "/Applications/HandBrakeCLI -i " & sourceFile & " -o " & quoted form of (tmpFile) & " --preset=\"AppleTV 2\" --main-feature;"
end if
--display dialog ConvertMovieCmd
do shell script ConvertMovieCmd
--short pause before copy
delay 10
--Replace Original
set ReplaceOriginalCmd to "mv -f " & quoted form of (tmpFile) & " " & destFold & "\"" & itemName & ".m4v" & "\""
--display dialog ReplaceOriginalCmd
do shell script ReplaceOriginalCmd
--Tag file with green label
set label index of theFile to 6
on error errmsg
--should conversion or copy fail display error message and continue with next file
--display dialog errmsg
set errorCount to errorCount + 1
--Tag file with red label
set label index of theFile to 2
end try
end tell
on error errmsg
--display dialog errmsg
end try
if errorCount > 0 then
mobile_alert("Conversion Failed " & quoted form of (itemName))
else
mobile_alert("Conversion Completed " & quoted form of (itemName))
end if
end timeout
return {hazelExportTokens:{itemName:itemName}}
end hazelProcessFile
Second step:
A resulting .m4v now sits back in the same source folder
If the color label is blank (this is the file that Handbrake produced in step 1) then run the embedded AppleScript
This passes the m4v to iFlicks for metadata and the sets the color label to Green when complete.

Step three:
When original .mvk is set to color label Green delete the file

So.... What I am trying to do is take the token from the ConvertVideo script (last lines in code above) and use it in the Import to iFlicks rule above.
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 7:08 pm
by ilium007
a_freyer wrote:First, I share Mr_Noodle's confusion as to why this is in multiple rules.
Happy for anyone to tell me how to do this properly - ie. by the sounds of it, in one rule only !
The one problem I do have with my setup is that subsequent rules are being blocked by rule 1. ie. everything ends up getting converted and added to iTunes - but what is happening (and you can see it from the screenshot) is that all files are being encoded (green label on the MKV files) before the next rule is processing them. I would like to have this so all steps are done in sequence - convert, add meta data and add to iTunes. Only then should it move onto the next MKV to process.
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 7:40 pm
by a_freyer
It seems like your workflow is fine. If it isn't broke, don't fix it. :-)
Would it be an option to add comments as I suggested?
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 8:10 pm
by ilium007
I will give that a go tonight. I do want to try and fix the blocking nature of my workflow. Hazels rules process differently than I thought. Obviously the rules process one by one and it seems that it is matching all on rule 1 before looking to make matches on rule 2.
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 8:23 pm
by a_freyer
Yeah - you do need to have unique matching for each rule if you want it to work sequentially. What Mr_Noodle was suggesting is executing all of your scripts sequentially in the same rule. Try that too.
Re: Custom tokens between rules

Posted:
Wed Aug 01, 2012 8:54 pm
by ilium007
Cool - I'll have a look into it. What I was trying to achieve was using the smarts of Hazel rather than writing all that logic into scripts. Maybe I will use additional folders with their own rules. So after the MTV is encoded drop it into a different folder with a hazel rule and have the encoded m4v file go into a third folder where it can be acted on straight away.
Re: Custom tokens between rules

Posted:
Thu Aug 02, 2012 3:22 pm
by Mr_Noodle
If you do separate the steps into different folders, then different Hazel processes will be handling each folder and therefore you can parallelize between those stages, if that's what you want.
Re: Custom tokens between rules

Posted:
Thu Aug 02, 2012 6:45 pm
by ilium007
What I ended up doing is changing the first AppleScript to push the encoded m4v to a new folder with another hazel folder watcher and adding the file delete to the first AppleScript. All working well now !