Find photo from directory in Photos App and mark it as favourite

I imported thousands of photos from my iPhone vis USB to my Mac using the Photos App. It preserved image edits, but lost the favourite label. I already put lots of effort into labelling photos as favourites on my iPhone, so I want to transfer the favourite labels from the iPhone to the photos in my Mac Photos App (I don’t have iCloud to do so).

To do so I copied all favourite photos from the iPhone to a separate flat Finder folder on my Mac.

Now I want to iterate through all photos in that Finder folder, open the according copy of each photo in the Photos App and apply the favourite label to it.

The process which I want to automate:

  1. Copy the creation date and the filename of the photo into the search field in the Photos App. This gives me exactly one matching photo.
  2. Click the photo and press “.” to label it as Favorite.
  3. Repeat with the next photo until reaching the end of the folder.

Can you help me how to automate this?

Ok. I wrote a script that’s capable of doing it. Saves tons of time.