You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

A sample AppleScript and some technical observations on Photos

Hi,


While I've had my own fair share of issues with Photos, I'm overall very happy with it. But I have noticed some quirks, so I thought I'd share them and also share an AppleScript I wrote to help out on some other discussions.


  1. Don't add a KeyWord to more than 1,000 photos at a time as a precaution. Photos crashed when I tried a huge huge number! And it didn't recover, so good job I use Time Machine religiously.

    I've found KeyWord updates in chunks of around 750 to be the best optimum

  2. Talking of Time Machine, I'd noticed that it doesn't backup the database files. I was going to try and research this, but when I lost 80% of my library (see point 1 above), it restored just fine.
    1. After restoring, and starting Photos, it displays a message knowing it has been restored, and does some re-building of the database. But it was a perfect copy. So, kudos to Apple for at least not losing me my library!
    2. On the two occasions in my life I have had to restore (one with iPhoto and the recent one with Photos), I find that the restore in Time Machine takes forever. So, I heartedly recommend this tip to use terminal to restore the library. With a USB3 hard drive, I restored an 85 GB library in around 25 minutes. Stack Exchange
  3. Smart Albums are not visible to AppleScript
  4. When changing or adding a title to an item in Photos, the change is not written to the database until you close Photos. Might be a good idea to close and reopen often if you are doing this much.
  5. I got loads of duplicates when I converted my iPhoto Library. It was a combination of a sync problem I had with PhotoStream and thousands of Zombie files that were hidden in my iPhoto package and imported into Photos during the conversion.
  6. I've been playing with AppleScript to help me tidy up my library. I wrote one script for another discussion, but I share it here, because it will give those that use AppleScript as an amateur (like myself) some clues on how to get a media item and do something with it.

    The documentation says that you can also process moments, but I haven't got that far yet!


I'll share the script and link in a separate post to make it easier to read!

MacBook Air, OS X Yosemite (10.10.3)

Posted on Apr 17, 2015 5:15 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 17, 2015 5:20 AM

I've been playing with AppleScript to help me tidy up my library. I wrote one script for another discussion, but I share it here, because it will give those that use AppleScript as an amateur (like myself) some clues on how to get a media item and do something with it. The documentation says that you can also process moments, but I haven't got that far yet!


There are some scripts about that use "get selection" but I have found this to be very buggy... as has the developer of Duplicate Annihilator. So, I recommend that you add the photos you want to process into an album and then use AppleScript on that album. Note: Applescript will not process SmartAlbums. You can use a SmartAlbum to get the selection of items you want... and then select all and add to a temporary album for AppleScript to use.


You can download this script from dropbox here, but I've also pasted the script below:


I personally don't run this script as an application or service... I prefer to open it in Script Editor and just hit run (or CMD/R). Make sure you have Photos open - I haven't put any checks in the script to wait for the app to open and be available to AppleScript.


Final warning: something odd about Photos: If you change the title of an item (either manually or with this script) it will not get written to the Photos database until you close the application. So, if you have changed any titles in preparation for running this script, make sure you close and reopen Photos. Also, if you are going to re-process any items that this script processed, you should as a precaution also close and reopen Photos. (BTW, for keywords, this is not a problem. They get written immediately.


-- Photos Filename to Title V1.0

-- Nic Fletcher - 17 April 2015


-- For a given album in a given folder, check if the image / video has a title

-- If not, make the title the same as the file name


-- NOTE: Photos does NOT write titles to the database (or at least so AppleScript

-- can see) until the application is closed. So, even after running the script

-- where you will see the new Titles displayed, if you re-run the script it will

-- reprocess the items. So always CLOSE and REOPEN if you have played with titles

-- before running this script.


tell application "Photos"

-- Album name you want to process. You could use a temp album at the top

-- level, and then you won't need to change the script every time

set albName to "Test Album"

-- If the albName is at the top level in Photos (i.e. not in a folder) then set this

-- to "True" - Set it to false to allow the script to fidn the album in a folder.

-- NOTE: This particular script will not process multiple levels in folders.

set topLevel to false

-- If the albName is in a folder (only one deep), set the name of the folder

-- here and make sure the topLevel varaiable is set to "False"

set albParent to "iPhoto Events"

if topLevel is false then

if existscontaineralbName of containeralbParent then

set myContainer to containeralbName of containeralbParent

--display dialog "SecondLevel Variable set"

else

display dialog "Folder or Album doesn't exist - Exiting" buttons ¬

"OK" with iconcautiondefault button "OK"

return

end if

else

if existscontaineralbName then

set myContainer to containeralbName

--display dialog "TopLevel variable set"

else

display dialog "Album doesn't exist - Exiting" buttons ¬

"OK" with iconcautiondefault button "OK"

return

end if

end if

set myCount to count of media items in myContainer

display dialog "About to process " & myCount & " item(s) in the container" as text

set n to 0

repeat with img in every media item of myContainer

set title to the name of img

if (count of title) = 0 then -- See comment about bug at bottom

set the name of img to the filename of img

set n to n + 1

end if

end repeat

display dialogn & " item(s) were processed" as text

end tell


-- Photos bug: If a title or keyword is deleted, Photos till thinks one exists!

-- So, need to count the number of characters to determine if it exists.

-- If a title or keyword never existed in Photos, then it will return not existing

37 replies

Feb 13, 2016 12:17 PM in response to NicFletcher

Hi Nic,

Your "Photos Filename to Title V1.3.scpt" is awesome!

I found after migrating from iPhoto to Photos that I had over 2,800 photos without titles. All of my photos now have titles after running your script. And it only took minutes! You saved me from spending countless hours creating titles from file names or abandoning Photos altogether.

Thank you very much!! I greatly appreciate it.

Aug 11, 2016 8:25 PM in response to NicFletcher

I am a 66 years old photographer and just move my large Aperture library to Photos . My pictures were named : my name_date_number . I have now imported some pictures in Photo and cannot find a way to do the same.


I just cannot believe than in 2016 , I have to write a script to be able to do that . Really !! I have been using Apple for many years but this is really non sense. So frustrated !! This application should not have been released as it is ! I understand that you are trying to help : Apple should hire all of you !!


Thanks Florence jean MBA, Inf

A sample AppleScript and some technical observations on Photos

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.