Page 1 of 1

Copy and Rename in the same folder at the same time...

PostPosted: Mon Jul 01, 2019 3:50 pm
by RMeira
Hi Mr.Noodle,

I need your help to do a simple task.

Example Filename
Teste - v1.pdf

When I add a tag "New Version" to this file I would like to create a copy of this file and rename to Teste - v2.pdf.

I need a more elegant solution.

Currently, I implemented this with 2 rules:

1st rule
run a shell cp "$1" "$1-HazelOldVersion"
rename using Hazel to the new version

2nd rule
file contains -HazelOldVersion
rename using Hazel taking out this "-HazelOldVersion"

Problem of the current solution is during the process the old file lost extension (.pdf became pdf-HazelOldVersion). Besides, its a not coordinate action. A new version is created and later - sometimes, really later - the old version file name is restored.


As I said, I need a better and more elegant solution.

Thanks in advance for your help and support.

Re: Copy and Rename in the same folder at the same time...

PostPosted: Tue Jul 02, 2019 10:14 am
by Mr_Noodle
Are you renaming the copy or the original? Also, is there a reason why you have this split up into two rules instead of one?

Re: Copy and Rename in the same folder at the same time...

PostPosted: Tue Jul 02, 2019 1:10 pm
by RMeira
That's the point!!!

I've been trying to do it in one single rule. I tried different approaches with no success.

Use Case
File - v1.txt when I add to this file a tag "New Version"
I want to duplicate file in the same folder to keep the version history and then rename the file to File - v2.txt.

I need your help!

Thanks!

Re: Copy and Rename in the same folder at the same time...

PostPosted: Wed Jul 03, 2019 10:46 am
by Mr_Noodle
Hazel's built-in copy action works such that subsequent actions operate on the copy. Instead of renaming it with a tag that you will remove anyways, why not copy the file to its destination without renaming it? Maybe you need to fill in more details on the workflow here.

Re: Copy and Rename in the same folder at the same time...

PostPosted: Sun Jul 07, 2019 11:26 am
by RMeira
Hi,
Point is Hazel Copy action always ask to a destination folder. I want to copy to the same folder - not a different folder.
If Hazel copy action allows me to create a copy at the same folder. it'll be very simple.
So, I decided to use a shell script with a cp command to create a new version of the file. I just don't know how to handle the filename string substitution to get a new version file. For example: cp "$1" <<I need help here to add 1 to the number after "-v" filename string>>
Considering $1 is /User/My Folder/File -v1-0.pdf"

Shellscript command ==> cp "$1" <<I need help here to handle filename string to get the new version "/User/MyFolder/File -v2-0.pdf">>

Can you help me here?

Thanks in advance for your help and support.

Best.

Re: Copy and Rename in the same folder at the same time...

PostPosted: Mon Jul 08, 2019 11:07 am
by Mr_Noodle
This is a bit outside of Hazel support. I suggest looking up more shell scripting specific places for help. I don't know the syntax off-hand but you can grab the separate parts of the path (the directory, the name and extension) so that you can re-combine them, adding the extra number.