Skip to content

Assign a photo’s Title field based on its filename in Photos

My migration from iPhoto to Photos continues, and today's snafu was my discovery that I couldn't rename files in Photos. This is something I've long done in iPhoto—not for every file, but for ones I'd like to group together using something other than Keywords.

For example, I have a collection of iOS wallpapers, for both the home and lock screens. I name each with either "H_" or "L_" as the start of the filename, which let me create this Smart Album to see them all together:

The inability to rename files isn't critical, in particular because the Title field can be used for the same functionality. But I had a problem: When I migrated, Photos created Titles for some, but not all, of my custom-named images. In particular, it missed all of the iOS wallpapers. I'm not sure if this is because these aren't photos in the traditional sense—they're edited photos I export as PNGs. But whatever the reason, I had hundreds of images that needed a Title that was equal to their Filename.

AppleScript to the rescue…this simple bit of code acts on the selection in Photos, and sets the Title equal to each image's filename.

To use this bit of code, just select the photos you'd like to modify in Photos, then run the script. You can make it a bit easier by saving the script into your user's Library > Scripts > Applications > Photos folder (create as many of those as don't exist). It will then be available in the AppleScript menu in the menu bar, assuming you've enabled that in the AppleScript Editor's preferences.

This saved me literally hours of work, copying and pasting filenames to the Title field. (I was surprised this worked, but it did—you can't change the filename, but you can select and copy it.)

April 28 2019 Update:

In the comments, Daryle W. asked about using this script when there wasn't a modified filename—he'd like to use the filename, but drop the extension. I did a quick bit of searching, and came up with the following, which seemed to work in my limited testing. Please have a good backup before trying this, as it's not nearly as well-tested as my original version.

This should work for any filename extension; I tested with JPG and HEIC and it worked fine. (I originally tried this without using a new variable, but it didn't work—I wasn't able to use the filename in the set cutPosition... line, for example.)

8 thoughts on “Assign a photo’s Title field based on its filename in Photos”

  1. How would you compare scriptability in Photos compared to Aperture? The extensive scriptable hooks in Aperture were one of the things that made it so awesome. I’m still on Mavericks so haven’t had a chance to check out the Applescript Dictionary for Photos.app to see how deeply they’ve embedded the scripting interface.

    1. I'm far from a scripting expert, but I'd describe Photos AppleScript support as relatively basic, especially when compared to Aperture. Here's a huge screenshot showing the dictionaries for each; Aperture's is clearly much deeper.

      -rob.

      1. Rob, this script was very helpful. I have over 500 pics with no title field, just a filename with a .jpg extension. Is there anyway to modify the script to drop the .jpg extension on the copy?

        1. Daryle:

          I added a second script to the post that should do what you want—please test it carefully before setting it loose on all 500 pictures :).

          -rob.

  2. Ah, I see the metadata support is pretty shallow - and manipulating EXIF and IPTC metadata fields was my main use for Aperture scripting. And of course that would be the one area where 3rd party developers would not be able to add much value to Photos…

  3. I've just used this script to fix the problem in High Sierra that prevented me from searching titles at all. I had 55,000 pics to index and I was damned if I was going to do that all over again. Thanks hugely!
    Matt

  4. Thank you for this script! Saved me hours. Unfortunate that Apple failed to include this basic functionality. Suspect Steve Jobs would not be happy.

Comments are closed.