Two files, one with added extension.

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

Moderator: Mr_Noodle

Two files, one with added extension. Tue Sep 10, 2013 10:14 am • by neotizz
Hi,

Im using Sabnzbd+ with Sickbeard and mp4tools for automatically muxing the file into .mv4
Sickbeard puts in my series folder, which activates mp4tools to mux it into .mv4

Now my question.
I would like Hazel to delete the downloaded *.mkv after m4tools processed it and added a new file *.mkv.mv4

I cant really find an answer to this 'problem'.

Can someone please help me? ive tried applescript with shell commands, but since this app should be so powerfull, maybe this is the solution.

Thanks!
neotizz
 
Posts: 1
Joined: Tue Sep 10, 2013 10:10 am

Re: Two files, one with added extension. Tue Sep 10, 2013 12:48 pm • by Mr_Noodle
If the only indication that the file has been processed is the existence of another file, then for the moment you'll have to use a script.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Two files, one with added extension. Sun Sep 15, 2013 6:50 am • by Skeo
I use shell scripting to make this work.
My setup is quite complicated, but for your purposes I would think something along the lines of:

Code: Select all
extension is .m4v
date last modified is not in the last 1 minute
passes shell script

    NAME=$(basename "$1" .m4v)
    if [ ! -e "$NAME" ]
    then exit 1
    fi

This will match your m4v file, 1 minute after it has finished processing and will only trigger if the original file exists in the same directory with the same name, less the .m4v extension. You could remove the 1 minute rule, but then you would risk the rule triggering before the file is finished processing.

I then use the shell to delete the original. Using shell scripts (or applescript) is the only way i've found to get hazel to act on a file other than the one that was matched.

Code: Select all
NAME=$(basename "$1" .m4v)
rm "$NAME"

Important to note here, that rm is unforgiving. The file is deleted immediately, which can be annoying if your m4v gets corrupted during processing.
If you'd rather move the originals to the trash and delete them manually when you are sure the conversion has worked, you can replace the rm command with a mv command.

Code: Select all
mv "$NAME" ~/.Trash
Skeo
 
Posts: 31
Joined: Mon Jan 02, 2012 7:53 pm

Re: Two files, one with added extension. Sun Sep 15, 2013 5:26 pm • by sjk
Skeo wrote:If you'd rather move the originals to the trash and delete them manually when you are sure the conversion has worked, you can replace the rm command with a mv command.

Code: Select all
mv "$NAME" ~/.Trash

Caveat: might not be desirable if the "$NAME" file is on a different volume than ~/.Trash is. Maybe there's a generalized "move to Trash on same volume" script out there?
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene

Re: Two files, one with added extension. Mon Sep 16, 2013 6:47 am • by Skeo
sjk wrote:Maybe there's a generalized "move to Trash on same volume" script out there?


I don't think you'll find a general command that will do that, but it wouldn't hard to write a script.
something like if $PWD contains /Volume/
then mv /Volume/$VOLNAME/.Trashes/$UID/
else mv ~/.Trash/
Skeo
 
Posts: 31
Joined: Mon Jan 02, 2012 7:53 pm

Re: Two files, one with added extension. Mon Sep 16, 2013 12:59 pm • by sjk
Thanks, Skeo. I've since found the trash command-line program that does intra-volume trashing utilizing Finder (by default). Works as advertised in my brief testing.
sjk
 
Posts: 332
Joined: Thu Aug 02, 2007 5:43 pm
Location: Eugene


Return to Support