Currently Being Moderated

Script: Batch Changing the Titles to the Filename w/Extension

In iPhoto the filenames have been as used as default titles and shown below the thumbnails in the browser.  Photos does not show the filenames as titles, and if a photo has no title, there is no identification visible in the browser, only in the Info panel.

To batch change the titles of photos without title, to make them visible below the thumbnails, you could try an Automator script I wrote to bring the titles back:

 

Note:  If you are using iCloud Photo Library scroll down to "Version2" -  the Apple Script version.  The Automator script version does not work well with iCloud Photo Library on Yosemite or El Capitan.

 

 

Create an Automator action, that executes an Apple Script to change the titles to the filename, if the title is empty:

 

The Apple Script:

 

on run {input, parameters}

tell application "Photos"

     activate

     set imageSel to (get selection)

     if imageSel is {} then

          error "Please select an image."

     else

     repeat with im in imageSel

          set title to the name of im

          if not (exists (title)) then

               set the name of im to the filename of im

          end if

     end repeat

     end if

end tell

end run


Launch Automator, create a new service, and drag a "Run Apple Script" action into the workflow.

Copy and paste the text above into the "Run Apple Script" action to replace the default text in the action.


Screen Shot 2015-04-23 at 12.35.02CEST.png

Save this workflow with a suitable name.  It will be installed in the services.

  • Now launch Photos and select a few test images.
  • Open the "Photos Menu > Services".
  • The service should be shown in the menu - I saved  my version as "filename2title".
  • Select the service to let it run. When you click the selected photos again, the titles should change.

 

Screen Shot 2015-04-12 at 02.19.56CEST.png

After the Automator action completed:

Screen Shot 2015-04-12 at 02.38.59CEST.png

 

 


I put a version of the Automator workflow here in my Dropbox:

  https://www.dropbox.com/sh/dzb49hg8rm8vjr8/AACvH-nRhY0B9su9PYR7em5Oa?dl=0

 

My script will just give you the general idea how to access filename and title in an Apple Script. For a more elaborate  AppleScript, with more error checks and removing the filename extension, check out the script that NicFletcher posted:

A sample AppleScript and some technical observations on Photos

 

For a discussion on how to improve this script, see:  Re: Re: Where are photo file names?

Re: Re: Where are photo file names?

 

 

 

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------

Version 2:  To be used with iCloud Photo Library

-------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------

 

This version of the script is to be run directly from the Script Editor.  The photos are not passed by selecting them in Photos but by collecting them in a top level album with the fixed name "PhotoDropBox".  All photos in this album will get their titles changed, when you press the run button in Script Editor.

 

 

-- batch change the title of images to the filename

(* How to use this script:

 

Open this script in Script Editor. Launch Photos.

 

The photos can be passed to the script in two ways:

1. Either select photos while viewing the  "All Photos" album; this works better than Moments or smart albums

2. Or collect the Photos in a top level defined album with a fixed name.

 

If you want to select the photos without collecting them in an album, set the variable "ReadFromAlbum" to false

If you want to pass the photos in a toplevel album, set ReadFromAlbum to true and change the variable "theAlbumName" to the name of the album you are using.

 

When all photos are selected or in the album and all parameters set, press the "Run" button in Script Editor.

 

*)

 

set ReadFromAlbum to true

-- set this to true, if you want to pass the photos in a toplevel album

set theAlbumName to "PhotoDropBox" -- change this to the name of the album you will use

 

 

set imageSel to {}

 

tell application "Photos"

  activate

  if (ReadFromAlbum) then -- the photos will be passed in a toplevel album named "PhotoDropBox"

 

  try

 

  if exists container theAlbumName then

 

  set thePhotosBuffer to container theAlbumName

  set imageSel to every media item of thePhotosBuffer

  else

  error "Album " & theAlbumName & "does not exist"

  end if

 

  on error errTexttwo number errNumtwo

  display dialog "Cannot open album: " & errNumtwo & return & errTexttwo

  end try

 

  else -- process the selected photos from the All Photos album

  try

  set imageSel to (get selection)

  on error errTexttwo number errNumtwo

  display dialog "Cannot get the selection: " & errNumtwo & return & errTexttwo

  end try

 

  end if

 

  -- check, if the album or the selected photos do contain images

  if imageSel is {} then

  error "Please select some images."

  else

  repeat with im in imageSel

  try

 

  tell im

 

  set its name to its filename

  end tell

  on error errText number errNum

  display dialog "Error: " & errNum & return & errText & "Trying again"

  try

  delay 2

  tell im

  set its name to its filename

  end tell

  on error errTexttwo number errNumtwo

  display dialog "Skipping image due to repeated error: " & errNumtwo & return & errTexttwo

  end try

  end try

  end repeat

  end if

end tell

-- display dialog "Done"

return "Done"

Replies

  • 11 Replies:

Delete User Tip

Are you sure you want to delete this user tip?