How to move a file after the file extension has changed

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

Moderator: Mr_Noodle

I have a folder into which .mkv files are placed. I have a Hazel rule that looks for the appearance of the .mkv files in that folder and runs an AppleScript that converts them to .m4v files using Handbrake. That all works fine. What I want after the conversion is for the rule to move those files to another folder. That is the part that fails.

From my investigation, I am getting messages in the log saying that the "file does not exist" and therefore the move fails. I believe the cause of this is that the only "if" condition I have is "is the file an .mkv". If so, then run the AppleScript and then the move.

I think that because the AppleScript is changing the file from an .mkv to a .m4v, then the 'move' is still looking for a .mkv and thus fails.

So, how would I change my rule to recognize the .mp4 and move it. Or, do I have to create a second rule for the folder that looks for .m4v?

Regards,

John
jormsby
 
Posts: 27
Joined: Mon Oct 13, 2014 7:04 pm

My guess is that the AppleScript is returning before the conversion happens. Therefore, the next action happens too early.

You would need to do a second rule to look for m4v. Given that the conversion takes time, I would add a condition like "Date last modified is not in the last X minutes" to prevent it from being moved before the conversion is done.
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for the response. By your statement that "the AppleScript is returning before the conversion happens", are you saying that the AppleScript tells Handbrake to start the conversion and once it does, then the AppleScript is finished and goes on to the move statement even though the conversion by Handbrake has only just started?

If so, I'm not sure that is it as both the mkv and the m4v files exist until after the conversion is complete. The last step of the AppleScript is to delete the old file (.mkv). Or have I misunderstood your statement.

With regards to your recommendation of look for an m4v and move based on that, I'm assuming I would have to make the "Date last modified" somewhere on the order of an hour or so, depending on how long the longest transcoding takes. Is that correct?

Regards,

John
jormsby
 
Posts: 27
Joined: Mon Oct 13, 2014 7:04 pm

Yes, depending on the AppleScript as well as the app being scripted, it may well be the case that the script just tells Handbrake to start and then continues on after that.

It would make sense both files exist during the conversion as the new file will contain the file being converted, even if it's incomplete.
Mr_Noodle
Site Admin
 
Posts: 11251
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support