Getting and setting file attributes for files in Finder selection

I need to store date modified data for a number of files selected in Finder, then perform an action in an app (writing metadata to the files using a Select or Show a Menu Item action), then restore the date modified for each file from the stored data.

I'm guessing I can probably do this using the For Each item in a collection action. My problem is I'm not sure how I can store the data in an array for each file, or access it by referencing the filename/path of each file to restore the stored modification date for each file selected in Finder.

I should also mention that there are commas in some of the filenames, and I'm stuck using KM 9.2 (on an old MacBook Pro running macOS Sierra 10.12.6).

Hopefully, someone can help me figure this out. Thanks in advance! :slight_smile:

Is the "perform an action in an app" going to act on all the files in the selection at once?

-rob.

Hi, @mz94.

Are you looking for one macro that completes all three steps or two macros, one that stores the modification dates and one that restores them (with some manual steps in between)?


If the former, you could modify this macro.

Download: Set File Attribute of Finder Selections (Option 1).kmmacros (4.4 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.4.1 (23E224)
  • Keyboard Maestro v11.0.2

If the latter, use this macro to save the modification date(s).

Download: Save Modification Dates (Option 2a).kmmacros (6.0 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.4.1 (23E224)
  • Keyboard Maestro v11.0.2

Complete the manual task(s).


Use this macro to restore the modification dates(s).

Download: Restore Modification Dates (Option 2b).kmmacros (8.4 KB)

Macro-Image


Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.

System Information
  • macOS 14.4.1 (23E224)
  • Keyboard Maestro v11.0.2

yes. the app is Soundminer. the action will embed edited metadata from the database in the app into the files, which will update their modification date. however, for various reasons, updating the modification date of the files in my sound library is highly undesirable.

I think I may need to use the separate steps because I will need to iterate through a large number of selected files in finder to store their modification date, then push metadata changes to all the files at once, and then iterate through the files again to restore the modification date for each of them.

Thank you for the proposed solutions! I'll take a closer look at each one and see which one might work best for this problem.

Okay, considering this additional information:

  1. Run macro Option 2a one or more times. Each time it is used, it will save the modification dates for each selected file(s). If all of the files are in one folder, then you can select them all, and run Option 2a once. If they are located in multiple folders, then you'll probably want to run Option 2a for each folder (with the files in each folder selected).

  2. Complete your manual steps.

  3. Run Option 2b (using the same approach used for Option 2a).

As it's currently designed, when Option 2b restores the modification date for the selected file(s), those saved modification dates are purged from the list of saved modification dates.

It would be a trivial change to retain those saved modification date(s) and only update the saved modification date(s) if Option 2a is run again for the file(s).

Note that the modification dates are saved into a dictionary. If you want to inspect the dictionary as you use Option 2a and Option 2b, then I suggest you download and use the excellent macro created and shared by @DanThomas: Variable Inspector Prompt and Dictionary Editor


Feel free to reach out if you have any questions.