Page 1 of 1

Copy most recent file, renaming at the same time

PostPosted: Tue Jan 09, 2018 4:54 pm
by prolost
I'm rendering frames from After Effects into a directory. I'd like Hazel to watch this folder for new PNG files, and when it finds one, copy it to a folder in my Dropbox. They key is that I want to rename as I copy, so the Dropbox folder only ever has one frame, the most recent. This way I can keep tabs on the render without filling up my Dropbox.

I tried creating a rule looking for Date Added is after Date Last Matched, and not being able to see how I could use the Copy action to rename on the fly, I tried the world's simplest embedded shell script:

Code: Select all
cp $1 ~/Dropbox/RenderWatch/MostRecentFrame.png


However, this returns an error every time.

Am I approaching this the wrong way?

Thanks in advance for any help.

-Stu

Re: Copy most recent file, renaming at the same time

PostPosted: Wed Jan 10, 2018 9:41 am
by Mr_Noodle
I believe you need the -f option to "cp" to force it to overwrite the destination.

Otherwise, you have a couple of options:
- Copy the file to a temporary location, rename it, then move that to Dropbox, with the move options set to overwrite.
- Copy the file to Dropbox then have Hazel monitor Dropbox and remove all but the most recent file. This is a bit more complex but it doesn't require a temporary location.

Re: Copy most recent file, renaming at the same time

PostPosted: Wed Jan 10, 2018 12:30 pm
by prolost
Thanks for the help! I tried -f as well, but still an error (exit code 64). The same cp command works fine in a shell.

In fact not even the most simple version of the cp command works, so I must be doing something wrong. This command reports the same error:

Code: Select all
cp $1 ~/Documents/


I set up a string of Actions like you suggest, and that works though, so I am up and running, thanks! The thing I didn't intuit is that all those actions applied to the results of the previous, i.e. if the first is copy, the second Action acts on the copied file. Now that I understand that, it was simple to set up what I needed.

You just converted a trial user to a paid customer, thanks!

But I'd still love to know why the most basic shell script is failing for me.

Re: Copy most recent file, renaming at the same time

PostPosted: Thu Jan 11, 2018 10:30 am
by Mr_Noodle
Are there spaces in the path? If so, then you need to put double-quotes around $1.

Re: Copy most recent file, renaming at the same time

PostPosted: Fri Jan 12, 2018 3:47 pm
by prolost
Man that really seemed like that must have been it, as there are spaces in the path. But even with the quotes, no luck.

Re: Copy most recent file, renaming at the same time

PostPosted: Mon Jan 15, 2018 11:04 am
by Mr_Noodle
Try using the full path instead of ~. Also, turn on debug mode as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

After that, check the logs to see if any errors/output from the script appear there.