rule to NOT move if folder contains anything

Talk, speculate, discuss, pontificate. As long as it pertains to Hazel.

Moderators: Mr_Noodle, Moderators

Im struggling to write a rule so after some help.

I have a folder with a folder action script attached which runs an instance of hanbrake cli, I have a hazel rule to move downloaded vids into this folder, handbrake then converts them and the files get moved onto flicks for importing to iTunes, however once more than one files are added the script won't run.
I want hazel to recognise that the folder already has a file in it, and not attempt to move any further files in it until that video is converted and moved out. Once the folder is empty, hazel can move then next file in.

All the rules analyse the contents of the monitored folder, not the folder to be moved to as far as I can see, has anyone got any ideas?

Thanks in advance.
simeonwest
 
Posts: 5
Joined: Sun Jul 10, 2011 3:37 pm

OK, I may have sorted this out myself within the confines of analysing the contents of a folder, not the contents of the folder to be added to.

My handbrake script adds a colour label to any processed file, and deletes the original. So, I have now got the folder with the script attached monitored by hazel, and any file without a colour label gets moved back out. In addition, Ive added a "not matched in the last hour" rule to the original moving rule, so once the files have been round in a circle once, they hopefully get ignored until the handbrake instance has finished processing.
simeonwest
 
Posts: 5
Joined: Sun Jul 10, 2011 3:37 pm

Why not have the rule that moves the file into the folder also run the script? That way each one is only processed one at a time?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

I did try this before, but to be honest I found this script on the internet, and not being very clued up with applescript I haven't modified it much. It's written as a folder action, and the only mods Ive made are to make it run in my folder structure, and to use the apple tv2 preset.
If anyone is able to modify it to run as a self contained applescript which i can run within hazel, I'd be grateful.

Here it is;

on adding folder items to this_folder after receiving added_items
with timeout of (720 * 60) seconds
tell application "Finder"
--Get all AVI and MKV files that have no label color yet, meaning it hasn't been processed
set allFiles to every file of entire contents of ("iTunes 2:downloads:Media files" as alias) whose ((name extension is "mkv" or name extension is "avi") and label index is 0)

--Repeat for all files in above folder
repeat with i from 1 to number of items in allFiles
set currentFile to (item i of allFiles)

try
--Set to gray label to indicate processing
set label index of currentFile to 7

--Assemble original and new file paths
set origFilepath to quoted form of POSIX path of (currentFile as alias)
set newFilepath to (characters 1 thru -5 of origFilepath as string) & "m4v'"

--Start the conversion
set shellCommand to "/Applications/HandBrakeCLI -i " & origFilepath & " -o " & newFilepath & " -e x264 -q 20.0 -r 29.97 --pfr -a 1,1 -E faac,copy:ac3 -B 160,160 -6 dpl2,auto -R Auto,Auto -D 0.0,0.0 -f mp4 -4 -X 1280 --loose-anamorphic -m"
do shell script shellCommand

--Remove the old file
set shellCommand to "rm -f " & origFilepath
do shell script shellCommand

on error errmsg
--Set the label to red to indicate failure
set label index of currentFile to 2
end try
end repeat
end tell
end timeout
end adding folder items to

Thanks
simeonwest
 
Posts: 5
Joined: Sun Jul 10, 2011 3:37 pm

This goes beyond the support I can give at the moment but I think if you search the forums, you might find a script to use Handbrake and from there tweak it to your liking.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

No problem, I'd left the question open rather than directing it specifically at you Mr Noodle.
My solution is working at the moment, so fingers crossed.
simeonwest
 
Posts: 5
Joined: Sun Jul 10, 2011 3:37 pm


Return to Open Discussion