Page 1 of 1

Changing a file's extension

PostPosted: Wed Sep 19, 2012 10:46 pm
by nguyenhimself
My goal is simple:

If there's a TXT file in the watched folder
Then Change the extension to MD

That's all I want.

I have a feeling that this should be rather obvious, since it's nothing but renaming. Still, my rule didn't work:

If ALL conditions are met for THE FILE OR FOLDER BEING MATCHED:
NAME matches (•Name).txt
Do
RENAME with (•Name).md

(with •Name as an Anything element.)

When I click the "Preview" button (bottom of the folder list, the txt file wasn't matched to that rule at all.

Thanks for your help.

Re: Changing a file's extension

PostPosted: Thu Sep 20, 2012 2:41 pm
by a_freyer
The short answer is that the "Name" element of the matching section of your rule ignores the extension. So, for your rule Hazel reads this:

(name •).txt.txt does not match (name •).txt

Your rule will work perfectly fine if you do this:

Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
    name matches (name•)
    extension is txt

Do the following to the matched file or folder:
    rename to (name •).md


However, I should say that unless you're changing the name of the file, a custom token is not necessary here because Hazel already tokenizes the filename. You could also do this to the same effect:



Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
    extension is txt

Do the following to the matched file or folder:
    rename to (name).md

Re: Changing a file's extension

PostPosted: Thu Sep 20, 2012 3:42 pm
by nguyenhimself
I knew there had to be a simple solution. Thank you!

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 6:57 am
by myildi
Hi,

Have this issue been solved in the current version? I do not have the impression.
When I check Replace text and introduce a change for the extension, it goes back to No Change as soon as I close the text change panel.

FYI: Build 875 here, under Mountain Lion.

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 10:05 am
by a_freyer
You'll have to be a bit more specific. The OP was not describing a bug. I'm surprised that there would ever be a need to replace text in an extension. What are you trying to replace within the extension ?

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 10:32 am
by myildi
a_freyer wrote:You'll have to be a bit more specific. The OP was not describing a bug. I'm surprised that there would ever be a need to replace text in an extension. What are you trying to replace within the extension ?


I have solved my problem directly in the bash script, but It would have been more elegant to do it using Hazel.

When I convert Markdown files in latex, html and OPML, I obtain extensions like myfile.md.tex, myfile.md.html using the $1 argument in the shell script.

I wanted to rename all these files by replacing the .md. part with . using the Replace text box of the name (or extension, none works in my case). Unfortunately I meet the above problem, the tag keeps the property "No change" even if I clicked on Text replace and given the above argument. Probably, I am not doing something correctly...

Since this does not work, I changed my bash script that calls the conversion commands of multimarkdown, by isolating the file name first and using it for renaming the output files in each conversion. That gives clean names like myfile.tex.

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 10:39 am
by a_freyer
I think your issue is that the EXTENSION token is the last period-delimited element. The NAME token will contain all the rest.

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 10:46 am
by myildi
a_freyer wrote:I think your issue is that the EXTENSION token is the last period-delimited element. The NAME token will contain all the rest.


I have tried to replace .md. in both, none makes it active and "No action" remains checked anyway. This is what perturbs me: why No action remains checked, while I have chosen the "Replace text" option? And nothing happens as a consequence (including my replacement request in the name part).

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 10:51 am
by a_freyer
To be absolutely clear, if we have:

myfile.md.tex

NAME = myfile.md
EXTENSION = tex

If you are replacing ".md" with "." in replace text, it should work. If it does not, then I believe that you have found a bug.

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 11:55 am
by myildi
a_freyer wrote:To be absolutely clear, if we have:

myfile.md.tex

NAME = myfile.md
EXTENSION = tex

If you are replacing ".md" with "." in replace text, it should work. If it does not, then I believe that you have found a bug.


Thank you very much. I was probably doing some stupid thing; this works now.
I must just replace .md in (name) with nothing and give (name)(extension) and renaming pattern to get:

myfile.md.tex -> myfile.tex

Strangely, the name tag continues to have "No action" checked, even if it seems to have registered my demand of replacing .md by an empty string. This was disorienting me (since I was not observing any real action either on the file names and extensions).

To summarize
Full solution: I can now search for files that have .md in their names and rename them using the (name)(extension) pattern where I replace .md with the empty string in the (name) tag.

But "No action" remains checked in the name tag even if it has registered my demand for text replacement.

Thank you very much for your help again.

Murat

Re: Changing a file's extension

PostPosted: Sun Oct 21, 2012 12:00 pm
by a_freyer
Sounds like a UI bug if the menu is simply not being selected, but the replace action is actually being performed. I'd suggest emailing mr_noodle from the support section of hazel.

Re: Changing a file's extension

PostPosted: Mon Oct 22, 2012 11:29 am
by Mr_Noodle
The "No change" item has nothing to do with replace text. It's only in regards to the other options in that part of the menu which affects capitalization. There is a separate between those options and the replace text option to indicate different domains in this case.