NicFletcher

Q: 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.
    1. 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.
    1. 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

Close

Q: A sample AppleScript and some technical observations on Photos

  • All replies
  • Helpful answers

Previous Page 2 of 3 last Next
  • by NicFletcher,

    NicFletcher NicFletcher Apr 19, 2015 4:23 PM in response to R C-R
    Level 1 (89 points)
    Apr 19, 2015 4:23 PM in response to R C-R

    Thank you!

     

    I actually struggled in the beginning, because I couldn't find a function that would read from right-to-left, and when I tried things like removing the last word in a string, I got 80% correct results, and the 20% that were wrong had no logic.

     

    But, while I am only an amateur (but use Google instead of Apple help), the source that helped me was several years old. So, it's probably been around for a long time.

     

    Nic.

  • by R C-R,

    R C-R R C-R Apr 19, 2015 4:59 PM in response to NicFletcher
    Level 6 (17,623 points)
    Apr 19, 2015 4:59 PM in response to NicFletcher

    I am just an amateur at this too, but I have been playing with Applescripts off & on pretty much since Apple introduced them back in the pre-OS X days. A not-so-great side effect of that is I tend to reuse some crusty old code that I know works (or at least used to) instead of checking out what Apple has added to newer versions like I should.

  • by NicFletcher,

    NicFletcher NicFletcher Apr 20, 2015 1:59 AM in response to R C-R
    Level 1 (89 points)
    Apr 20, 2015 1:59 AM in response to R C-R

    All:

     

    I made a mistake in an earlier post.

     

    It is perfectly possible to get Smart Album containers.

     

    I think I came to this conclusion early in playing with Photos, and I was failing for different reasons. But I have tested, and I can easily get the Smart Album and do anything with it that I can with any container (doh... it's a container)!

     

    Apologies for the confusion.

  • by smbjerke,

    smbjerke smbjerke Apr 29, 2015 11:24 AM in response to NicFletcher
    Level 1 (4 points)
    Photography
    Apr 29, 2015 11:24 AM in response to NicFletcher

    Hi Nic,

     

    Your script worked like a dream and saved the day for me - I would otherwise have dumped Photos and gone for a 3rd party package as replacement for Aperture. Many thanks ! (And let me know if you make further improvements.... )

     

    Regards,

    Sjur

  • by ArthurAJ,

    ArthurAJ ArthurAJ Jun 6, 2015 2:03 PM in response to NicFletcher
    Level 1 (0 points)
    Jun 6, 2015 2:03 PM in response to NicFletcher

    Your script works very well for me. I'm delighted.

    I do have a question and that concerns the processing of a large album. I haven't had any problems with processing albums with hundreds of photos. But I did have a problem when I came to one that had 1339 photos. Interestingly the script processed 1310 photos and then I got an error that said: "Photos got an error: AppleEvent timed out."

    I'm assuming that the time out is because of the volume of photos I'm processing. Is there a way to lengthen whatever time timed out? And if not, since we're identifying a folder and then an album in the folder, how would you suggest I process just a partial folder?

    Thanks for your help, I very much appreciative it. I'm trying to work with Photos but finding a few things that I wish were different. I've used iPhoto and then Aperture but since those are both unsupported now, I really can't find much of anything in the way of a photo library software package that lets me do what I've done in Aperture (and I'm not all that excited about editing within my library - except for the simple basic editing tools that are there already). But I digress.

    Thanks

    Art

  • by ArthurAJ,

    ArthurAJ ArthurAJ Jun 6, 2015 10:39 PM in response to ArthurAJ
    Level 1 (0 points)
    Jun 6, 2015 10:39 PM in response to ArthurAJ

    Well, I don't know if my post above is true or not now. Maybe my computer was doing some other action that took away from the applescript running and that caused the timeout. I thought that if I put the following at the top of the tell script…

                        with timeout of (30 * 60) seconds

                               Tell application "Photos"

                                     Statements

                                     Statements

                                     Statements

                                End Tell

                          End timeout


    …that it would keep the script running for 30 minutes before it quit. However, as I tried processing an album that had 6994 photos, I found that after 30 minutes the script continue to run and process photos (only about 1500 or so - a long way from 7K) and it continued to run through 3156 of the photos before deciding to stop, a little over one hour. I still have half of the album to process but that's where I am now (BTW - the album is for the full year of 2013).

     

    It was a little hard not knowing where the script was in relation to its progress though. And I did some checking and discovered that in Yosemite's system there is now support for a progress counter. I found an example that could be run from the script editor and perhaps be integrated without too much difficulty in the Photos replace title with filename script. But I tried unsuccessfully to make it work and went back to the original script.

     

    Anyway, my issue with the timeout is moot, I suppose!

     

    Thanks for reading.

     

    Art

  • by NicFletcher,

    NicFletcher NicFletcher Jun 7, 2015 5:28 PM in response to ArthurAJ
    Level 1 (89 points)
    Jun 7, 2015 5:28 PM in response to ArthurAJ

    Hi ArthurAJ!

     

    Thanks for your feedback.

     

    (For new readers, see the sample scripts at the end of this post)

     

    Before I answer your specific questions in your two posts, I'd like to say that in the beginning, I suffered very much with the change from iPhoto to Photos (I've never used Aperture, so I cannot comment). But, now I love Photos. But it took some time. There are some quirks, and some big omissions (e.g. not being able to add a geo location) and from the Apple Script side it is very buggy. I'm trying hard not to say that Apple know best, and certainly the first release of Photos is far from perfect, but now with a couple of months usage, I've got used to it.

     

    In summary: If I know the date and / or the location, then I can find my photos pretty quickly. There's no real need to have titles (unless you have historic photos form the days when we used name our photo files in Finder as a way of cataloging them). I confess, that I do set up a Smart Album for the current month, and then when the new month starts I copy the contents to a regular album, so I can replicate the old Photo Stream monthly albums). But otherwise, I realise that (just Google with Gmail) when searching is so easy and powerful, wasting time with cataloging is not really that useful.

     

    But anyway (I also - like you - seem to digress), to ANSWER your QUESTIONS:

     

    1. The AppleEvent timeout seems to be a big issue with the AppleScript implementation with Photos. The whole AppleScript side of photos is simply somewhat buggy in my opinion.

    2. The single biggest thing you can do to minimise its effect is to ALWAYS have the album you are processing displaying in Photos while you run any script. It makes a huge huge difference.

      I haven't tested more than 1500 photos in one album, so maybe even making sure that Photos is open and displaying the album you are processing still won't solve these bugs if the album is extra large.

    3. Your question on how to split an album: I've done this simply by selecting say, the first thousand items, and then adding the to a temporary album and then running a script against the temporary album. And then emptying the album and adding the next thousand items. And so forth.

    4. As for the timeout and adding timeouts to Apple Script, my limited testing has shown it makes little difference. This is substantiated for many other posts in forums. If making sure the album being processed is being displayed in Photos while the script is running doesn't make a difference, then you will simply need to manually create a temp album with a subset of the main album to process against (point #3 above).

    5. As to the process indicator, I have added one to the script you are using. You can download it here: Photos Filename to Title V1.3

      The process indicator in Yosemite cannot be used in a dialog box for a script, so your will see it on the status bar of Script Editor (i.e. the bottom).

    6. I also created and posted a "sample / test" script a while back to share with amateurs like myself my findings with Photos and AppleScript. For some reason I can't find that post, but you can see that script here: Testing with Photos V1.0

      This is not a specific script to do anything, but that rather a sharing of my experiences. It's a script with different sub routines to share my (trial and error) experiences with Photos and Applescript. I can't find my original post with this, but you take a look and learn from that script here: Testing with Photos V1.0

    Good Luck!

     

    Nic.

  • by ArthurAJ,

    ArthurAJ ArthurAJ Jun 7, 2015 8:05 PM in response to NicFletcher
    Level 1 (0 points)
    Jun 7, 2015 8:05 PM in response to NicFletcher

    Nic,

    Thanks for the response. I appreciate the time and effort you taken to write scripts and to give counsel to amateurs, like me, who try to do things that perhaps it would be better if they didn't. But, I am seeking to learn, now that I've retired, and dealing with my library of about 30,000 photos and my wife's library on her computer of about 70,000 photos (she needs professional help, I think). We both started out with iPhoto back when iPhoto was brand new and I eventually graduated to Aperture when it arrived. Just about 3 years ago I convinced my wife to migrate to Aperture because she was so frustrated with iPhoto. But when I became disillusioned with Aperture I returned occasionally to iPhoto and then to other software solutions as well. But when Apple decided to abandon Aperture AND iPhoto I was in hopes that the new Photos app would take the best of those apps and put it into one. But alas, I was very disappointed, but stuck, because there isn't much of anything else to choose from without paying a hefty subscription fee for Adobe Lightroom to get other programs I don't want or purchase some other very expensive tools that have so much more than I would ever ever use. So, I tested and tested again in Photos and am trying to make a go of it. My wife, however, doesn't feel that it would work for her and she's sticking with an abandoned Aperture. Sigh! But on to your response.

     

    1. I do have photos I've scanned that go back to 1911 and I want them to have dates that reflect that. But replacing dates is a very dodgy experience in many programs because of the system not wanting to go back to a time before digital. But Photos does let me change the dates and they stay in their appointed albums nicely.

     

    2. I have finished processing my 30K of files in Photos with your script. The largest album contained almost 7,000 photos. I did keep the album displayed and didn't do other things while the script was running. It processed every album with a time out, even the largest album. I was replacing titles and not skipping titles I had already put in place. I did notice on one album that the timeout error dialog appeared while I was away from the computer. I figured that it hadn't processed all the files, but in fact it did. I believe the error dialog came because I didn't respond to the dialog that said the job was finished. That's just my guess.

     

    3. I haven't checked out your progress added script, but I will. I think that many years ago I created an Applescript for some jobs I was trying to do at my office, and found a script for a horizontal barber pole progress bar that I was able to integrate into my script and it worked great. But, I don't have that script anymore and Applescript has changed a lot since those early days. I always try to make sense of every aspect of a script before using it and nowadays there are things that have me scratching my head and wondering what it all means. Thank you for making available your modified script for me and others.

     

    If you gotten this far in my post, thanks for reading! You've been a great help!

     

    Art

  • by NicFletcher,

    NicFletcher NicFletcher Jun 8, 2015 6:31 AM in response to ArthurAJ
    Level 1 (89 points)
    Jun 8, 2015 6:31 AM in response to ArthurAJ

    You are very welcome.

     

    I also recall something about the blue barber pole several years back, but it was very very convoluted and not easy I seem to recall.

     

    In any case, the new progress indicator in Yosemite, is ONLY available if you run the script in Script Editor. There is no way to display this indicator if you run it as an app or outside of Script Editor.

     

    However, you could try something with display dialog box... display a dialog box with the current number (you can use your own count or why not the AppleScript's progress completed steps) quitting after a few seconds and redisplaying say every time the count gets to a certain rounding (say 100 or 50). I've done that in the past.

     

    I'm not saying Photos is perfect (there is some small truth to some people's complaints about dumming down OS X to iOS), but as time goes on, I find myself less and less concerned about the loss of some of the iPhoto features.

     

    Good Luck!

  • by cgar55,

    cgar55 cgar55 Jun 17, 2015 6:49 PM in response to NicFletcher
    Level 1 (0 points)
    Jun 17, 2015 6:49 PM in response to NicFletcher

    Had an odd behavior with v1.2 script: On first launch it processed almost exactly half of the images in the designated album before aborting with the message "The action “Run AppleScript” encountered an error."  Subsequent runs repeated this behavior (divide by 2) until finally there was only one image remaining, which was processed with a final pass.  Anyone else experiencing this?

     

    Otherwise, great script covering Apple's deficiency in this area!  Thanks NicFletcher.

  • by Getawaypaul27,

    Getawaypaul27 Getawaypaul27 Jun 21, 2015 8:00 AM in response to NicFletcher
    Level 1 (0 points)
    Jun 21, 2015 8:00 AM in response to NicFletcher

    Nic, thanks for sharing this. It's been very helpful and has saved me so much time. I have a follow-up question though:

     

    I want to share some pictures through Photos and have the description (which was originally the filename) viewable. Unfortunately, Photos doesn't show the title or description of a picture when it is shared. However, I am able to add a comment to each photo.

     

    Is it possible to edit your script so that the filename is set as my comment in a shared photo stream? Or do you know of another way for to have the description viewable when sharing pictures with others via Photos?

  • by Gabes McDonald,

    Gabes McDonald Gabes McDonald Jul 8, 2015 4:54 PM in response to NicFletcher
    Level 1 (0 points)
    Jul 8, 2015 4:54 PM in response to NicFletcher

    Nic:

    Thanks very much for the script.   I titled 988 pics in one swipe.    I do have one question, when I move any "titled" pic to a shared "folder/album", it doesn't bring the title with it.   I did try manually entering a title for a pic but that didn't work as well.   Any ideas?

  • by NicFletcher,

    NicFletcher NicFletcher Jul 10, 2015 4:36 AM in response to Gabes McDonald
    Level 1 (89 points)
    Jul 10, 2015 4:36 AM in response to Gabes McDonald

    Hi Gabe,

     

    As far as I am aware, it is NOT possible to have a title or a description when sharing photos in an album.

     

    The shared albums are not available to AppleScript (they are not in the dictionary, and I didn't find a way with trial and error).

     

    I guess Apple, as they go for iOS centric, think this is not needed. In the beginning this also bugged me, but I tend not to worry so much now. If I share photos, I tend to share one album on a subject, so it's not really necessary to label every photo. And if I'm sharing a big album with family, they already know the context. I'm not defending Apple per se, but I realise my life has become actually easier since using Photos.

     

    Glad the script could help otherwise!

     

    Nic.

  • by NicFletcher,

    NicFletcher NicFletcher Jul 10, 2015 4:38 AM in response to Getawaypaul27
    Level 1 (89 points)
    Jul 10, 2015 4:38 AM in response to Getawaypaul27

    Sorry, no! The shared albums are not available to AppleScript. They are technically (I believe) part of iCloud and not Photos - even though we view and manage them through Photos. I've also not found a way for descriptions or titles to follow into sharing. Makes no difference for those using iOS, because they can't see these anyway.

     

    Nic.

  • by Gabes McDonald,

    Gabes McDonald Gabes McDonald Jul 10, 2015 5:07 AM in response to NicFletcher
    Level 1 (0 points)
    Jul 10, 2015 5:07 AM in response to NicFletcher

    thx for taking time to check it out

Previous Page 2 of 3 last Next