Move Certain File to Trash

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

Moderator: Mr_Noodle

Move Certain File to Trash Fri Mar 22, 2024 7:11 pm • by klind
I have over 3K directories containing videos. I am in the process of reducing the size of many of these videos by converting them from .MKV files to .MP4 files. All is going well until I want to get Hazel to delete the duplicate .MKV files. How can I search for any given subdirectory that contains two files with the same name and then move only the .MKV file to trash. I've tried coding the .MP4 file with a tag and I can find it OK, but I need to move the opposite file. Is this possible?
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Mon Mar 25, 2024 9:31 am • by Mr_Noodle
First off, please do not post Hazel issues to the Forum/Site Discussion section. That is for issues related to the website.

Look up nested conditions in the manual. You can set up something like:
Code: Select all
If (all) are met
    Extension is mkv
    If (all) are met for (any file in the same folder)
        Name matches (name)
        Extension is mp4


That will match an mkv file is there is an mp4 file with the same name in the same folder. You may need to tweak that for your specific case but that should give you a starting point.
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move Certain File to Trash Mon Mar 25, 2024 5:09 pm • by klind
Thank you for the response. I hope you moved this post appropriately. I will try to do better in the future.
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Mon Mar 25, 2024 7:06 pm • by klind
Mr Noodle, sir, your much appreciated response has left me with an additional question.

Code: Select all
If (all) are met
    Extension is mkv
    If (all) are met for (any file in the same folder)
        Name matches (name)
        Extension is mp4


How can I enter the (name) to match as I am running this through many sub-directories with many files of a different name. I see I could use matches (anything), and that would probably work, but it seems to me that using (anything) could be dangerous. Also you didn't suggest (anything), you suggested (name). How do I get the name of the file that is found in the first part where extension is mkv?
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Tue Mar 26, 2024 9:10 am • by Mr_Noodle
(name) is the built-in Name attribute. It represents the name of the file currently being matched.
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move Certain File to Trash Mon Nov 04, 2024 2:37 am • by klind
OK, (name) is a built in attribute. So I should be able to get a green check beside the condition Name matches (name)... but I cannot. I have tried and tried. I have studied the nested conditions pages and the attributes and actions and the custom attributes and the built in attributes. So why is this condition always red and never green?

I have written an AppleScript that converts files moved into a particular folder to pdf. That action leaves me with two files with the same name and different extensions. I want to simply automate moving the non-pdf file to the trash folder. I have tried many variations of this without success. Here are two:

Code: Select all
If (all) of the following conditions are met
    Extension is pdf
    If (all) of the following conditions are met for (any file or folder in the same folder)
        Name matches (name)
        Extension is not pdf
Do the following to the matched file or folder
    Move to folder Trash


Code: Select all
If (all) of the following conditions are met
       Name matches (name)
       Extension is pdf
          If (all) of the following conditions are met for (any file or folder in the same folder)
              Name matches (name)
              Extension is not pdf
   Do the following to the matched file or folder
       Move to folder Trash


I have tried (name), (Name), (File Name), (file name), name, Name, and more but the red X denoting that the rule does not match does not change. I was not able to find anything in the site documentation describing how to use the built in attributes. If anyone has had success with this please provide guidance... Thanx.
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Mon Nov 04, 2024 11:07 am • by Mr_Noodle
Name (on the left hand side) in this case is not the name of the file being match, but the name of other files in the same folder. So no, it will not always be green. Can you show a screenshot of the preview along with one of Finder showing these two files with the same name?
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move Certain File to Trash Mon Nov 04, 2024 4:37 pm • by klind
1. Unlike other forums this forum does not allow for posting screenshots.

2. I do not understand what you mean by preview... preview of what? If it is "Preview of a rule" it changes as the rules are executed.

Starting out the folder is empty, as is the preview of the rule.

I move a text (.txt) file into the folder and Finder now shows one file titled 'Test File.txt'. Hazel executes my first rule calling an AppleScript and creates a file titled 'Test File.pdf''. The Finder pane now shows two files, 'Test File.txt' and Test File.pdf'. The preview of rule shows two files 'Test File'txt' and 'Test File.pdf'.

Now I want to delete the .txt file, but only if the .pdf file with the same name exists. Nothing I have tried in months has been able to accomplish this. I provided two examples of rules I have tried. There are many more. I have also tried rearranging the rules (there are only two at the moment). I have tried with 'Continue matching rules' and 'Run rules on folder contents' both individually and jointly in different order.

Since the red X does not change and since I can manually point click and delete the .txt file, there must be some facet of Hazel rule design I simply do not understand. Although my desired Hazel workflow is complicated, my query is simple, how do I delete the .txt file after the .pdf file is created and in existence? I have dozens of Hazel rules and I love using Hazel, but there isn't much (if any) help anywhere on the net concerning creating rules when one needs to cascade conditions. I have watched dozens of YouTube videos, purchased and watched McSparky Field Guide, joined Automator sites, etc. Is it not possible for more explicit guidance. I just bet I am not alone out here...
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Tue Nov 05, 2024 10:11 am • by Mr_Noodle
If you don't have your own cloud service to post images, then use a service like imgur.com. Please post a pic of your rule in preview mode.
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move Certain File to Trash Tue Nov 05, 2024 4:04 pm • by klind
Paul, I am sure you are a very busy person and I sincerely apologize for disturbing your day, but as I previously stated, I do not understand what you mean by "in preview mode".

Regardless, I have posted a copy of the rule here: https://imgur.com/a/wvfQ5f4
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Wed Nov 06, 2024 9:52 am • by Mr_Noodle
Yes, that is preview mode. So it looks like you entered my rule in literally. You are not supposed to enter the text "(name)". You are supposed to drag in the "name" attribute that appears below the field.
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move Certain File to Trash Wed Nov 06, 2024 4:51 pm • by klind
OK, I see. I'll give that a try later today. Is there somewhere in the manual where use of built in attributes is explained? If so, I couldn't find it.

Thanx for this fast response...
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Fri Nov 08, 2024 12:17 pm • by Mr_Noodle
Look up match patterns in the manual.
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Move Certain File to Trash Fri Nov 08, 2024 5:45 pm • by klind
I have done as you ask... Read the manual... Repeatedly. I can not find "the "name" attribute that appears below the field."

What 'field'? What do you mean by 'field'? How do I make it 'appear'? I just want to know how to select built-in attributes. Why is that so difficult? I know that when I start typing with an open paren '(' a small pane opens that looks like this:

(1)
(2)
(3)
(4)
(name)

None of these let me 'drag', however I can select one of them such as '(name)' by clicking it. I have done that and it looks exactly like my screenshot that you said is wrong. Besides, when I use the 'extension' selection and start the response with a paren it still opens the same pane as I show above.

All I want to do is move a .ext file with the same name as a different .ext file in the same folder to the trash. Given this:

onefile.txt
onefile.pdf
twofile.jpg
twofile.pdf
threefile.pages
threefile.pdf

I want to delete the non-pdf files.

BTW, what do the numbers in paren's in the drop down do?
klind
 
Posts: 55
Joined: Mon Jan 30, 2017 7:02 pm

Re: Move Certain File to Trash Mon Nov 11, 2024 10:37 am • by Mr_Noodle
Sorry, looking at your screenshot again is missed that you use "Name is". You need to use "Name matches".
Mr_Noodle
Site Admin
 
Posts: 11685
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Next

Return to Support

cron