0

I'd like to export all of my favorited photos/videos on a weekly basis to a zip file or directory. Is there an apple script/automator workflow that can do this that I can schedule to run?

Thanks for your response, I've tried what you suggested but get this error (please note that automator is automatically changing the text "using originals true" to "with using originals": enter image description here

user1542125
  • 593
  • 6
  • 16

1 Answers1

3

If we open up the scripting dictionary for Photos and search for “favorite”, we see the following:

“favorites album” in Photos scripting dictionary

There is an album object available from the root Photos application that contains all of your favorited items. Perfect! Now we need to export them… dictionary, what do you have to say on the matter?

“export” command in Photos scripting dictionary

There is a command in Photos that exports specified media items to a filesystem location. That's exactly what we need! So, so far, we have this in our script window:

tell app "Photos"
    export every media item in favorites album to [export location here] ¬
        using originals true
end

Obviously, you should replace [export location here] with the location you want to export to (via a file or POSIX file specifier). If you want to compress them into a zip file now, that should be pretty easy, too. In this case, since this functionality isn't provided by any preinstalled system application (that I am aware of), we can outsource the job to a command line utility called zip:

set quoted_out_location to quoted form of POSIX path of [export location here]
do shell script "zip -r " & quoted_out_location & space & quoted_out_location

And that's it! From there you can move the resulting zip file wherever you need using System Events or Finder or whatever you please, and delete the intermediate folder if you want. If this needs to run automatically on a regular basis, the easiest option by far is to embed the script in an Automator Calendar Alarm workflow, and attach it to a recurring calendar event. That's not too hard to find with a quick Google search, and this answer is long enough already.

ThatsJustCheesy
  • 1,370
  • 14
  • 24
  • Thanks for your response, it was helpful but I'm getting an error (see my original post for screenshot). – user1542125 Apr 16 '18 at 10:17
  • @user1542125 You're almost there! Stuff like that is a known issue with the AppleScript system… try this: `export (get every media item in favorites album) to destination with using originals` What that does is it first retrieves `every media item of favorites album` and then tells Photos to _that_. You can also solve this with an intermediate local variable; it would do the same thing. The "with using originals" thing is just something AppleScript does when it sees a boolean command parameter: it converts it to `with`/`without` `paramName`. – ThatsJustCheesy Apr 16 '18 at 15:20
  • Oh, and also: don't convert `destination` back to `text`, just leave it as a `POSIX file`: `POSIX file` is actually just a pseudoclass, and whenever AppleScript sees one, it is immediately converted to a `file` under the hood. The `export` command specifies that it wants a `file` in the scripting dictionary, so I would leave it as that. – ThatsJustCheesy Apr 16 '18 at 15:34
  • Great that seemed to fix it. However now I'm getting "Photos got an error: AppleEvent timed out." error and no images are exported. Any ideas? – user1542125 Apr 17 '18 at 09:11
  • Actually I have a hunch that the issue is with referenced photos...I'll see what I can do about that. – user1542125 Apr 17 '18 at 09:13
  • Thank you for your thorough response and help. – user1542125 Apr 21 '18 at 06:54