Rubberdonkey

Q: automator: import to specific photo album in photos

Hi, I want automator to import into a specific sub-level photo album. Automator only lets me choose the top-level albums, but not the ones inside folders.

But Hazel can do this, however, I want to do this in automator to write a little program that accepts photos and imports them into a specific album in a folder in photos.

Anyone an idea?

 

thanks a lot.

 

I am using El Capitan.

Posted on Oct 8, 2015 2:44 PM

Close

Q: automator: import to specific photo album in photos

  • All replies
  • Helpful answers

  • by Jacques Rioux,Solvedanswer

    Jacques Rioux Jacques Rioux Oct 10, 2015 12:52 PM in response to Rubberdonkey
    Level 4 (3,408 points)
    Mac OS X
    Oct 10, 2015 12:52 PM in response to Rubberdonkey

    Hi,

     

    It's possible with an AppleScript, but the album's name must be unique.

     

    Remove the "Import ..." action in your workflow

    Add the  "Run AppleScript" action, clear the default text, copy/paste this script:

     

    on run {input, parameters}
          tell application "Photos"
                set thisAlbum to album "some album Name"
                import input into thisAlbum without skip check duplicates -- or --> with skip check duplicates
          end tell
          return input
    end run
    
    

     

    Change the album's name in the script.

     

     

    ---

    If the album's name is not unique, you can specify an album with his parent folder, like this :

    set thisAlbum to album "some album name" of folder "some SubFolder name" of folder "some Master name"

  • by Rubberdonkey,

    Rubberdonkey Rubberdonkey Oct 11, 2015 6:44 AM in response to Jacques Rioux
    Level 1 (4 points)
    iCloud
    Oct 11, 2015 6:44 AM in response to Jacques Rioux

    Hi Jaques,

     

    I tested your code, but Automator tells me that my album name "Abstrakt und Textur" cannot be converted to integer.

     

     

     

              on run {input, parameters}         

           tell application "Photos"

                set thisAlbum to album "Abstrakt und Textur" of "Portfolio"    

                import input into thisAlbum with skip check duplicates         

           end tell

      return input

    end run

  • by Rubberdonkey,

    Rubberdonkey Rubberdonkey Oct 11, 2015 7:33 AM in response to Rubberdonkey
    Level 1 (4 points)
    iCloud
    Oct 11, 2015 7:33 AM in response to Rubberdonkey

    Oh, I forgot "folder".

     

    It worked, thanks.

     

    Now, I actually want to import from a specific folder. I know how to do this, but I only want new photos.

    So whenever I put new photos in my test folder and I run this script, I want automator to import the new photos (just the new ones) into photos in my album.

     

    I don't know how I can check wether a photo is new.

    In hazel i would do the following rule: if date created is after date last matched. But how do I doe this in applescript?

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Oct 11, 2015 10:03 AM in response to Rubberdonkey
    Level 4 (3,408 points)
    Mac OS X
    Oct 11, 2015 10:03 AM in response to Rubberdonkey

    Hi,

     

    Rubberdonkey wrote:

     

    Now, I actually want to import from a specific folder. I know how to do this, but I only want new photos.

    So whenever I put new photos in my test folder and I run this script, I want automator to import the new photos (just the new ones) into photos in my album.

     

    I don't know how I can check wether a photo is new.

    In hazel i would do the following rule: if date created is after date last matched. But how do I doe this in applescript?

     

     

    You can create an Automator (Folder Action) , a folder action run when a file(s) is created, dropped or copied into a specific folder, the input will be the added file(s).

     

     

    Or, if you want a script that checks the file creation date, you can use this script

     

    on run {input, parameters}
        try -- read the preference file to get the date
            set lastD to date (do shell script "defaults read me.aut.myWorkflowPref  lastImportDate")
        on error -- catch the error on the first run, because no plist file
            set lastD to (current date) - (1 * days) -- set the start date to your need
        end try
        set newFiles to {}
        copy lastD to thisnewerDate
       
        -- loop to check the creation date of the files
        repeat with i in input
            set d to creation date of (info for i without size)
            if d > lastD then
                set end of newFiles to contents of i -- add this file to a list
                if d > thisnewerDate then copy d to thisnewerDate
            end if
        end repeat
    
        -- store the date (thisnewerDate) to a plist file
        do shell script "defaults write me.aut.myWorkflowPref  lastImportDate " & quoted form of (thisnewerDate as string)
       
        -- import newer files to Photos
        if newFiles is not {} then
            tell application "Photos"
                set thisAlbum to album "Abstrakt und Textur" of folder "Portfolio"
                import input into thisAlbum with skip check duplicates
            end tell
        end if
        return newFiles
    end run
    
    

     

     

    This script read or write the date (the newer creation date) from a plist file in your Preferences folder.

    if the PLIST file does not exist, then the script will create the plist file (his name will be "me.aut.myWorkflowPref.plist")

  • by Rubberdonkey,

    Rubberdonkey Rubberdonkey Oct 12, 2015 11:40 AM in response to Jacques Rioux
    Level 1 (4 points)
    iCloud
    Oct 12, 2015 11:40 AM in response to Jacques Rioux

    thanks. I didn't know, that a folder action simply solves my problem.

     

    One last question. Is there a way to embed a code in the script wich prevents photos from showing the notification "imported 1 photo" ?

    I could turn off notifications for Photos completely, but I don't want that. Can Applescript prevent single notifications?

     

    I really need to learn applescript. Do you have any recommendation on a book or something?

     

     

    Again, thank you for your time, I really appreciate your support.

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Oct 13, 2015 10:55 AM in response to Rubberdonkey
    Level 4 (3,408 points)
    Mac OS X
    Oct 13, 2015 10:55 AM in response to Rubberdonkey

    Hi,

     

    Rubberdonkey wrote:

     

    One last question. Is there a way to embed a code in the script wich prevents photos from showing the notification "imported 1 photo" ?

    I could turn off notifications for Photos completely, but I don't want that. Can Applescript prevent single notifications?

     

    You can disable and enable Photos's notifications by script (sqlite3's commands from a Shell), like this

    on run {input, parameters}
        -- disable Photos's notifications , set the flag to 8262 = no notification
        do shell script "cd `getconf DARWIN_USER_DIR`/com.apple.notificationcenter/db/ && sqlite3 db \"UPDATE app_info SET flags='8262' where bundleid='com.apple.Photos'\" && killall usernoted"
      
        tell application "Photos"
            set thisAlbum to album "Abstrakt und Textur" of folder "Portfolio"
            import input into thisAlbum with skip check duplicates
        end tell
      
        -- enable Photos's notifications: (default flag : banners = 8270), alert = 8278
        do shell script "cd `getconf DARWIN_USER_DIR`/com.apple.notificationcenter/db/ && sqlite3 db \"UPDATE app_info SET flags='8270' where bundleid='com.apple.Photos'\" && killall usernoted"
        return input
    end run
    

     

     

    ---

    Rubberdonkey wrote:

     

    I really need to learn applescript. Do you have any recommendation on a book or something?

     

     

     

    See this page --> https://discussions.apple.com/docs/DOC-4901