Keeping the newest version of file based on filename

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

Moderator: Mr_Noodle

Hi all

Been doing some digging around, and I've found some posts that seem to suggest I could do what I'm asking, but I can't seem to modify the previous solutions to do what I want (I've never been an AppleScripter, so the best I can do there is copy/paste unfortunately). I was wondering if someone might be able to help, or even link me to a missed post that gives me the info I'm looking for.

I would like Hazel to go through my dmg/pkg files and find delete the older versions of files based on the filename (same filename just gets overwritten if I download it). So for example, "LittleSnitch-3.6.dmg" and "LittleSnitch-3.7-nightly-(4710).dmg", in this case I'd like to delete the 3.6 file.

Any thoughts or links would be greatly appreciated.

Cheers.
BigJazzz
 
Posts: 21
Joined: Fri Aug 12, 2016 9:38 pm

Checking version numbers would require a script and may be tricky, depending on the version numbering system the developer uses.

An alternate way to do things is to do "Date added is not among the 1 most recent, move to trash". The problem is that it applies to all files in that folder, and not just the LittleSnitch ones, for example (see thread here about changing this behavior: viewtopic.php?f=2&t=6760).

This unfortunately leads back to square one where you'll need a script.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

The files I'm mostly interested in are ones that use a [Program]-[string of numbers].[ext] pattern. So I guess something along the lines of

If the program name matches, and the string of numbers are different, keep the higher string.
If name matches, and no string, ignore.
If name doesn't match, ignore.

I'm completely happy to have to occasionally delete things on my own, just would like a broad rule to catch most things.
BigJazzz
 
Posts: 21
Joined: Fri Aug 12, 2016 9:38 pm

BigJazzz wrote:The files I'm mostly interested in are ones that use a [Program]-[string of numbers].[ext] pattern. So I guess something along the lines of

If the program name matches, and the string of numbers are different, keep the higher string.
If name matches, and no string, ignore.
If name doesn't match, ignore.

I'm completely happy to have to occasionally delete things on my own, just would like a broad rule to catch most things.


Apologies for resurrecting an old thread but I too am interested in seeing if this is possible.
Anjadekar
 
Posts: 24
Joined: Sat Jun 03, 2017 4:33 pm

+1 for this. Very much needed...
luhmann
 
Posts: 2
Joined: Fri Sep 08, 2017 12:28 am

Note that "is among the" behaves differently now. If you do something like:
Code: Select all
    If (all) are met
        Name is <some app name>
        Version is among the 1 highest


that will match the most recent version. Note that "Version" here is a Spotlight attribute which theoretically should contain the version number of an app (so it isn't derived from the name). Also, this assumes that the version numbers can be compared like decimal numbers which is not the case for a lot of developers (Hazel included).
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support