Page 1 of 1

Keeping the newest version of file based on filename

PostPosted: Fri Aug 12, 2016 9:54 pm
by BigJazzz
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.

Re: Keeping the newest version of file based on filename

PostPosted: Mon Aug 15, 2016 11:11 am
by Mr_Noodle
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.

Re: Keeping the newest version of file based on filename

PostPosted: Tue Aug 16, 2016 1:14 am
by BigJazzz
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.

Re: Keeping the newest version of file based on filename

PostPosted: Tue Jul 11, 2017 3:37 pm
by Anjadekar
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.

Re: Keeping the newest version of file based on filename

PostPosted: Fri Sep 08, 2017 12:29 am
by luhmann
+1 for this. Very much needed...

Re: Keeping the newest version of file based on filename

PostPosted: Fri Sep 08, 2017 10:34 am
by Mr_Noodle
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).