Ziatron

Q: Old Toad did some great scripts for Photos, but I need one more

Old Toad did some great scripts for Photos, but I need one more.


A script that would copy the Keywords to Titles might be my answer.

 

http://www.oldtoadstutorials.net/No.P01.html

 

You see, I started with iPhoto and later started using Aperture.  With iPhoto and Aperture you can have ANY metadata shown below the Thumbnails, (nice).  Well, I put descriptions of all of my images in the Keywords section because it really didn't matter, because these programs could show them below the Thumbnails.

 

Now I'm using that wonderful    Photos program and I have discovered that it will ONLY show the "Title" of the image below the thumbnails.  I've got about 30,000 images with Keywords but no Title.  I would like to move / copy the text from the Keyword section into the Title section. I'm no computer expert, I guess that my skills are average.  But I can follow directions. 


A script that would copy the Keywords to Titles might be my answer.

Posted on Apr 28, 2016 12:26 PM

Close

Q: Old Toad did some great scripts for Photos, but I need one more

  • All replies
  • Helpful answers

  • by léonie,Apple recommended

    léonie léonie Apr 30, 2016 1:07 AM in response to Ziatron
    Level 10 (105,806 points)
    iCloud
    Apr 30, 2016 1:07 AM in response to Ziatron

    To get you started, try this script: I tested it on OS X 10.11.4 

      Only try it on small test library, and be sure to have a working backup of your library.

     

    The script is not yet perfect, it will glue the keywords in the titles together without separators, so you still will  have some editing to do. The handling of text separators in apple Script is so tedious, that I did not have time to handle that.

     

     

     

     

    -- batch change the title of images to the keywords

    (* 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 all photo are selected or in the album and all parameters set, press the "Run" button in Scripteditor.

    *)

     

    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

      -- retrieve the keywords

      set kws to its keywords as string

      if not (exists kws) then

      set kws to ""

      end if

     

      --retrieve the old title

      set thename to its name

      if not (exists thename) then

      set thename to ""

      else

      set thename to thename & " "

      end if

      set its name to thename & kws

      end tell

      on error errText number errNum

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

      try

      delay 2 -- wait and try again

      tell im

      -- retrieve the keywords

      set kws to its keywords as string

      if not (exists kws) then

      set kws to ""

      end if

     

      --retrieve the old title

      set thename to its name

      if not (exists thename) then

      set thename to ""

      else

      set thename to thename & " "

      end if

      set its name to thename & kws

      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"

  • by Ziatron,

    Ziatron Ziatron May 5, 2016 2:36 PM in response to léonie
    Level 4 (3,924 points)
    Apple Watch
    May 5, 2016 2:36 PM in response to léonie

    Sorry for the delay in replying.  We were recently dumped from Verizon, (very reliable) to Frontier.   I had no Internet for 6 days.

     

    Wow !

     

    I had no idea that scripts were so complicated.  I have never done a script before.  Should I learn about scripts first?

     

    All of your programming steps below?  Is that something I copy into something somewhere ?

     

    I do have a couple of small libraries I could try this on. Where exactly do I start?

  • by léonie,Apple recommended

    léonie léonie May 5, 2016 11:09 PM in response to Ziatron
    Level 10 (105,806 points)
    iCloud
    May 5, 2016 11:09 PM in response to Ziatron
    I had no idea that scripts were so complicated.

     

    Scripting is writing a program. To understand how it works, open the Script Editor from Applications > Utilities and click "Help".

    Try "Show Apple Script Language Guide". It will show you the basics.

     

    The script is looking a bit complicated, because I added several error tests to make it robust. - all the parts starting with "try".

     

    Basically:  This tells the application "Photos" to launch

    tell application "Photos"

      activate

     

    Then the script is selecting  an album - you add the name of the album here, my default is "PhotoDropBox"

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

     

    This is retrieving all photos in the album:

    set imageSel to every media item of thePhotosBuffer

     

    And now all photos in the album are told to retrieve their keywords:

     

    repeat with im in imageSel

      try

      tell im

      -- retrieve the keywords

      set kws to its keywords as string

      if not (exists kws) then

      set kws to ""

      end if


    This line tells the image I'm to copy the keyword to the name - the new name will be the old name wth the keywords appended.


      set its name to thename & kws



    To run a script, copy and paste the code into an empty "Ne w Script" window in the Script Editor and click the Run button.


  • by Old Toad,

    Old Toad Old Toad May 7, 2016 11:15 AM in response to léonie
    Level 10 (140,918 points)
    Photos for Mac
    May 7, 2016 11:15 AM in response to léonie

    Just to make the record clear (am I sounding like a politician here?) I did not create any of the scripts in the user tips. Most were created by léonie, some at my request  and posted by me and others by herself or others' requests.  My scripting ability is rudimentary at best, limited to opening or closing files, apps or volumes.

  • by léonie,

    léonie léonie May 7, 2016 11:22 AM in response to Old Toad
    Level 10 (105,806 points)
    iCloud
    May 7, 2016 11:22 AM in response to Old Toad

    Now you are too modest

  • by Old Toad,

    Old Toad Old Toad May 7, 2016 11:26 AM in response to léonie
    Level 10 (140,918 points)
    Photos for Mac
    May 7, 2016 11:26 AM in response to léonie

    Good reply.  Vote for me and we'll make Photos create again.

  • by léonie,

    léonie léonie May 7, 2016 11:30 AM in response to Old Toad
    Level 10 (105,806 points)
    iCloud
    May 7, 2016 11:30 AM in response to Old Toad

    Let me know when you start campaigning

  • by Old Toad,

    Old Toad Old Toad May 7, 2016 11:41 AM in response to léonie
    Level 10 (140,918 points)
    Photos for Mac
    May 7, 2016 11:41 AM in response to léonie

    I have been for several months now.  I guess the subliminal campaigning model isn't working too well.