Ziatron

Q: Help using leonie / Old Toad move text from "Keywords" to "Titles"

Need help using leonie / Old Toad move text from "Keywords" to "Titles".

 

I have 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.


So, I tried this Script:   Append Keywords to Title Field - Léonie's Script


It somewhat does the job, but not completely. 


When I select an image in Photos, and then, "Get Info" I will see the below in the title area, note that the first two lines are identical.


IMG_2621.JPG

IMG_2621.JPG

March 12, 2014  2:23 PM


My Keywords are:   Experimental Engine 17 at 600 Hours


AFTER I run the Script, I get the below:


IMG_2621.JPG - Experimental Engine 17 at 600 Hours

IMG_2621.JPG

March 12, 2014  2:23 PM


I need this to be: 


Experimental Engine 17 at 600 Hours

IMG_2621.JPG

March 12, 2014  2:23 PM


I don't understand why Photos shows the file name twice.   These fields are not labeled, but I was under the impression that the top line was the Description, the second line is the File Name, and the third line is the Date.   Because only the top line is shown under the thumbnails, I am trying to have the maximum amount of descriptive information appear in that area, (just as we could do with iPhoto or Aperture in the past).


In other words, when I run the script I would like my Keywords to completely replace everything in the top line, eliminating the file name. Is there anything wrong with this approach?  I would still have the file name in the second line, right?


Thanks.


Posted on Jun 10, 2016 8:42 AM

Close

Q: Help using leonie / Old Toad move text from "Keywords" to "Titles"

  • All replies
  • Helpful answers

Page 1 Next
  • by Old Toad,

    Old Toad Old Toad Jun 10, 2016 4:38 PM in response to Ziatron
    Level 10 (140,898 points)
    Photos for Mac
    Jun 10, 2016 4:38 PM in response to Ziatron

    Remove the file name from the Title field and then run the script. You'll get

     

     

    - Experimental Engine 17 at 600 Hours

    You can manually remove the "-" at the beginning or modify the script.

  • by Ziatron,

    Ziatron Ziatron Jun 10, 2016 6:38 PM in response to Old Toad
    Level 4 (3,924 points)
    Apple Watch
    Jun 10, 2016 6:38 PM in response to Old Toad

    Remove the file name from the Title field and then run the script.

    Well, I was hoping to do this automatically with the script.  Going through 30,000 images to remove the File Name is something I would like to avoid.   Is there any way to have the script do this for me?

     

    You can manually remove the "-" at the beginning or modify the script.

     

    I am just trying to have the exact text in Keywords moved to the Title field, (Top line in, "get info").   So I would like to eliminate the "-" using the script.  Is this possible?

     

    I'm assuming the second line after, "get info" is the actual, true Filename.   It's useful to keep the true Filename intact in case images are found elsewhere, and I want to see if that image is contained in the Photos app.

  • by Old Toad,

    Old Toad Old Toad Jun 11, 2016 9:19 AM in response to Ziatron
    Level 10 (140,898 points)
    Photos for Mac
    Jun 11, 2016 9:19 AM in response to Ziatron

    So I would like to eliminate the "-" using the script.  Is this possible?

    Yes.  You would change both occurrences of the following code in the script:

    end if

    set its name to thename & "- " & kws

    end tell

    to

    end if

    set its name to thename & kws

    end tell

    In other words, remove

    & "- "

  • by léonie,

    léonie léonie Jun 11, 2016 9:34 AM in response to Ziatron
    Level 10 (105,599 points)
    iLife
    Jun 11, 2016 9:34 AM in response to Ziatron

    Ziatron,

    The Info panel is showing first the title of the image and below that the filename.

     

    If you are seeing the filename twice, you must have copied the filename to the title field to display it below the thumbnails a the title.

     

    The script I wrote is appending the keywords to an existing title. This is happening in these lines.

     

    --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

     

    You could simply replace these lines by a modification of the last line:

    set its name to kws

    Then the title will only contain the keywords.

  • by Old Toad,

    Old Toad Old Toad Jun 11, 2016 9:52 AM in response to léonie
    Level 10 (140,898 points)
    Photos for Mac
    Jun 11, 2016 9:52 AM in response to léonie

    léonie:

     

    You're a true Apple Genius. 

  • by léonie,

    léonie léonie Jun 11, 2016 10:23 AM in response to Old Toad
    Level 10 (105,599 points)
    iLife
    Jun 11, 2016 10:23 AM in response to Old Toad

    Thanks for the compliment OT. From you it is praise indeed!

  • by Ziatron,

    Ziatron Ziatron Jun 11, 2016 11:05 AM in response to léonie
    Level 4 (3,924 points)
    Apple Watch
    Jun 11, 2016 11:05 AM in response to léonie

    First and most importantly, leonie, and Old Toad, thank you very much for sticking with me on my problem.  My problems are rooted back in the days of iPhoto when ANY metadata could be specified to go below the Thumbnails.    Unfortunately, I made the mistake of using the Keywords field to describe my images.  The new Photos app puts us all in a tighter box because of the things it will not do. I'm trying to make adjustments with all of my images so I can move forward with Photos.  Again, thanks to both of you so much for helping me.

     

    If you are seeing the filename twice, you must have copied the filename to the title field to display it below the thumbnails a the title.

     

    I absolutely never did that. I have no idea how the filename got copied to the title field.   I looked through some of my images, (I have about 15 Photos libraries). All the images that I looked at do show the file name also in the title field.   I have a couple of Photos libraries that I use for temporary purposes and for eBay. These images were never given any Keywords or descriptions by me. Yet, the filename and Title field are identical!   I can only guess that as these images moved from iPhoto to Aperture to Photos something went, "sideways".

     

    Can I assume, that the script we are working on will still work if it comes across images where the title field is blank?


    Remember, my goal is to have the words or phrases from Keywords moved / copied into the Title field exactly as it is, replacing anything that is currently in the Title field.


    I have attempted to modify the script following the instructions from you and Old Toad.   Could you look the below over and see if I did this right?



    ************************************************************************

     

    -- return AppleScript's text item delimiters

     

    set ReadFromAlbum to false

    -- 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 {}

    set saved_delimiter to AppleScript's text item delimiters --save the delimiter

     

     

    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 the text item delimiter

      set AppleScript's text item delimiters to {", "} --use a space as the delimiter

      -- 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

      set AppleScript's text item delimiters to {", "} --use a space as the delimiter

      -- 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 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

     

    **************************************************************************

  • by Ziatron,

    Ziatron Ziatron Jun 11, 2016 9:41 PM in response to Ziatron
    Level 4 (3,924 points)
    Apple Watch
    Jun 11, 2016 9:41 PM in response to Ziatron

    Well, I tried to compile the script above but I got the below message.

     

    Syntax Error

    Expected end of line, etc. but found unknown token.


    I took a look at the Script Editor, I couldn't find any clues where the error is.


    Advice or suggestions appreciated.

  • by léonie,

    léonie léonie Jun 11, 2016 11:47 PM in response to Ziatron
    Level 10 (105,599 points)
    iLife
    Jun 11, 2016 11:47 PM in response to Ziatron

    The error message indicates an incorrect block structure, some missing "end".

     

    I modified my original script (including OT's changes) and put it into my Dropbox:

    https://dl.dropboxusercontent.com/u/45503699/PhotosBatchChangeTitleToKeywordsAlb umReplace.scpt.zip

     

    There is a new variable "replace_old_title". If this is set to "true", any old title will be completely overwritten by the list of keywords.

     

     

    -- 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.

     

    By default the old title will be overwritten.  If you want to append to the old title, set the variable replace_old_title to false.

    When all all photo are selected or in the album and all parameters set, press the "Run" button in Scripteditor.

    *)

     

     

    set ReadFromAlbum to false

    set replace_old_title to true -- change this to false, if you want to append to the previous title

     

    -- 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 {}

    set saved_delimiter to AppleScript's text item delimiters --save the delimiter

     

     

    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 the text item delimiter

      set AppleScript's text item delimiters to {", "} --use a comma and space as the delimiter

      -- retrieve the keywords

     

      set kws to its keywords as string

      if not (exists kws) then

      set kws to ""

      end if

     

      if (replace_old_title) then

      set thename to "" -- the old title will be overwritten

      else

      set thename to its name

      if not (exists thename) then

      set thename to ""

      else --retrieve the old title

      set thename to thename & ", "

      end if

      end if -- (replace_old_title)

      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

      set AppleScript's text item delimiters to {", "} --use a comma and space as the delimiter

      -- retrieve the keywords

      set kws to its keywords as string

      if not (exists kws) then

      set kws to ""

      end if

     

     

      if (replace_old_title) then

      set thename to "" -- the old title will be overwritten

      else

      set thename to its name

      if not (exists thename) then

      set thename to ""

      else --retrieve the old title

      set thename to thename & ", "

      end if

      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"

    set AppleScript's text item delimiters to saved_delimiter --restore  the delimiter

     

    return "Done"

  • by Ziatron,

    Ziatron Ziatron Jun 12, 2016 11:47 AM in response to léonie
    Level 4 (3,924 points)
    Apple Watch
    Jun 12, 2016 11:47 AM in response to léonie

    Hello léonie,

     

    I used the script from the dropbox.  I opened up one of my smaller Libraries and selected 2 images to test that have Keywords.  I then ran the script. Nothing happened! I waited about 30 minutes and then tried to close the Script Editor. I got the following message, "The document can't be closed while the script is recording."  I don't understand what this means.

     

    When I ran the earlier script that appended Keywords to Titles it completed more or less instantly.  In this earlier test, I just selected two images from my Library.

  • by léonie,

    léonie léonie Jun 12, 2016 11:51 AM in response to Ziatron
    Level 10 (105,599 points)
    iLife
    Jun 12, 2016 11:51 AM in response to Ziatron

    Are you using iCloud Photo Library?

  • by Ziatron,

    Ziatron Ziatron Jun 12, 2016 12:22 PM in response to léonie
    Level 4 (3,924 points)
    Apple Watch
    Jun 12, 2016 12:22 PM in response to léonie

    Are you using iCloud Photo Library?

     

    No.   I only use the cloud with my contacts, nothing else.

  • by léonie,

    léonie léonie Jun 12, 2016 12:31 PM in response to Ziatron
    Level 10 (105,599 points)
    iLife
    Jun 12, 2016 12:31 PM in response to Ziatron

    Then I don't know, sorry. The script in my Dropbox is working for me.

     

    "The document can't be closed while the script is recording."  I don't understand what this means.

    Did you perhaps click the "Record" button instead of the "Run" button?

  • by Ziatron,

    Ziatron Ziatron Jun 12, 2016 12:54 PM in response to léonie
    Level 4 (3,924 points)
    Apple Watch
    Jun 12, 2016 12:54 PM in response to léonie

    Did you perhaps click the "Record" button instead of the "Run" button?

     

    Yes     VERY sorry !!!!

     

    As I understand your script I can open a given Library and then select the images I want to, "process".   In my little test, I only selected 2 images.

     

    I have backed up all of my libraries  So, AFTER I get your Imprimatur I will go ahead and try to process some larger libraries and select all of the images.

     

    As you may recall, I have the, "mystery issue" of the filename being copied into the title field. Below you will see before, and after, "get info" screenshots.

     

    Screen Shot 2016-06-12 at 2.45.24 PM.png

     

    Screen Shot 2016-06-12 at 2.47.27 PM.png

Page 1 Next