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

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

Moderator: Mr_Noodle

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.
RMeira
 
Posts: 15
Joined: Thu Apr 27, 2017 3:22 pm

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?
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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!
RMeira
 
Posts: 15
Joined: Thu Apr 27, 2017 3:22 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

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.
RMeira
 
Posts: 15
Joined: Thu Apr 27, 2017 3:22 pm

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.
Mr_Noodle
Site Admin
 
Posts: 11195
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support