macos – Set Date Modified to oldest of selected files in Finder?

Spread the love


Advertisement

I figured it out! I needed to do both: sort the selected input files as arguments and use a for loop to modify each selected file.

Advertisements

Here's the shell script I ended up adding as a Service in Automator (receives files & folders in Finder.app, pass input as arguments):

oldest=$(stat -f "%m:%N" "[email protected]" | sort -n | head -1 | cut -f2 -d:)

for f in "[email protected]"; do

    touch -r "$oldest" "$f"

done

I also figured I would add a similar Service to do the same thing, except setting the date modified of all selected files to match that of the newest selected file. Here's the shell script I ended up adding as a Service in Automator for that (receives files & folders in Finder.app, pass input as arguments):

newest=$(stat -f "%m:%N" "[email protected]" | sort -rn | head -1 | cut -f2 -d:)

for f in "[email protected]"; do

    touch -r "$newest" "$f"

done

Hope this proves useful for others who may have a similar problem and stumble upon this question and the solution I found for the issue.

Author: Subham

Leave a Reply

Your email address will not be published. Required fields are marked *