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

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.

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

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.

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

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

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

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'sprogress 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!

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.

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?

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.

Dec 25, 2015 8:21 AM in response to NicFletcher

Hi, Script noob here. I tried a few of the scripts, and the app, and all don't seem to want to start. I tried selecting individual or groups of images, iphoto events (in photos), albums, nothing seems to matter. What do I need to do/select before I launch the service, or after?


For the dropbox long version, I get the welcome splash screen (This script will search for media items missing...) then: Album or Folder doesn't exist - exiting.


For the App, I got: Photos got an error: AppleEvent handler failed. (-10000)

Thanks.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

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.