AppleScript or Automator flow to import photos into iphoto and set album name as files folder name

StackOverflow https://stackoverflow.com/questions/16824335

  •  30-05-2022
  •  | 
  •  

Question

I store photo files in folders on my computer before i add them into iphoto.

I want to add the contents of a selected to folder to iphoto and name the new album as the folder name

I have created an automator flow where I do the following

(Select folder initially to work)

  1. Get selected finder items -- This is grabbing the folder
  2. Set Value of Variable -- this is grabbing the full path name and setting a variable with the name
  3. Get Folder contents -- this gets all the photos contained.
  4. Import Files into iphoto -- This adds the photos into iphoto and creates a new album using the variable name.

The issue i have is the variable name sets the full path of the files, /Users/Johnny/Photos/Dayout

Is the a script that can take just the name of the initial folder "Dayout"

Thanks in advance to anyone who can help

Cheers

John

Was it helpful?

Solution

activate application "SystemUIServer" -- http://www.openradar.me/9406282
tell application "Finder"
    activate
    repeat with f in (get selection as alias list)
        set n to name of f
        tell application "iPhoto"
            if not (exists album n) then new album name n
            import from f to album n
        end tell
    end repeat
end tell

There is a bug in 10.7 and 10.8 where Finder ignores new windows when getting the selection property. If you open a new Finder window, select some items, and run tell app "Finder" to selection in AppleScript Editor, the result is items selected in some window behind the frontmost window (or an empty list). One workaround is to move focus to another application and back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top