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.