Hey, I pieced together an applescript from various parts of this site. I have been able to write a script to import images from a Finder folder into iPhoto. However I want to be able to choose from three optiions what album/event/or create new album to put the images into. I couldnt find my answer here or google so i thought I would call out for some help.
Here is the script that I am working with.
set theFolder to alias "Video:Users:London:Desktop:To iPhoto:"
tell application "Finder"
try
move items of theFolder to "Video:Users:London:Documents:iPhoto Import Temp:"
on error
display dialog "[Video/Users/London/Documents/iPhoto Import Temp] could not be found" buttons {"OK"} default button 1
set theFolder to choose folder
end try
tell application "iPhoto"
import from alias "Video:Users:London:Documents:iPhoto Import Temp:"
repeat while importing
delay 1
end repeat
tell application "Finder"
delete files of alias "Video:Users:London:Documents:iPhoto Import Temp:"
end tell
end tell
end tell
Hi,
events are not accessible by AppleScript because actually they are a special view of the library.
Try this
set theFolder to ((path to desktop as text) & "To iPhoto:")
set tempFolder to ((path to documents folder as text) & "iPhoto Import Temp:")
set albumName to missing value
set {button returned:b} to display dialog "Import Images to." buttons {"Cancel", "Library", "Album."}
if b = "Album." then
set {text returned:albumName} to display dialog "Enter Album Name" default answer ""
end if
tell application "Finder"
try
move items of folder theFolder to folder tempFolder
on error
display dialog "[Video/Users/London/Documents/iPhoto Import Temp] could not be found" buttons {"OK"} default button 1
set theFolder to choose folder
end try
tell application "iPhoto"
if albumName is missing value then
import from alias tempFolder
else
if not (exists album albumName) then new album name albumName
import from alias tempFolder to album albumName
end if
repeat while importing
delay 1
end repeat
end tell
tell application "Finder"
delete files of folder tempFolder
end tell
end tell
Do you really need the temp folder? You could import directly from the folder on desktop
Thank you very much, yeah I got rid of the temp folder, however there are couple issues. The first one is when I choose the Album… option it imports the album but does not import the images into iphoto at all, i know the script finishes because files are deleted. I would like to be able to choose from a list of album names that already exist in iPhoto so I can directly import the images into those albums.
Changes I made to the applescript
set theFolder to ((path to desktop as text) & "To iPhoto:")
set albumName to missing value
set my_title to "iPhoto Import from Folder"
set {button returned:b} to display dialog "Import Images to." buttons {"Cancel", "Library", "Album."} with title my_title
if b = "Album." then
set {text returned:albumName} to display dialog "Enter Album Name" default answer ""
end if
tell application "iPhoto"
try
if albumName is missing value then
import from alias theFolder
else
if not (exists album albumName) then new album name albumName
import from alias theFolder to albumName
end if
on error
display dialog "[Video/Users/London/Documents/iPhoto Import Temp] could not be found" buttons {"OK"} default button 1
set theFolder to choose folder
end try
repeat while importing
delay 1
end repeat
end tell
tell application "Finder"
delete files of folder theFolder
end tell
set theFolder to ((path to desktop as text) & "To iPhoto:")
set albumName to missing value
set my_title to "iPhoto Import from Folder"
set {button returned:b} to display dialog "Import Images to." buttons {"Cancel", "Library", "Album."} with title my_title
if b = "Album." then
tell application "iPhoto" to set albumList to name of albums whose type is regular album and name is not "Flagged" and name is not "Last Import"
set albumName to choose from list albumList with prompt "select an album"
if albumName is false then return
set albumName to item 1 of albumName
end if
try
tell application "Finder" to set theFiles to files of folder theFolder
repeat with oneFile in theFiles
tell application "iPhoto"
if albumName is missing value then
import from (oneFile as alias)
else
import from (oneFile as alias) to album albumName
end if
end tell
end repeat
tell application "Finder"
delete files of folder theFolder
end tell
on error e
display dialog "an error occured: " & e buttons {"Cancel"} default button 1
end try
Awesome, there was just one problem that when it imported the images it wouldn’t wait for import so I added:
repeat while importing
delay 1
end repeat
after each import.
works fine.
But there is still one last thing I want to be able to do. Instead of having the images import to Library. I would rather have a New Album button that would allow me to change the name of the album. Thank so much for all your help btw.
set theFolder to ((path to desktop as text) & "To iPhoto:")
set albumName to missing value
set my_title to "iPhoto Import from Folder"
set {button returned:b} to display dialog "Import Images to." buttons {"Cancel", "Library", "Album."} with title my_title
if b = "Album." then
tell application "iPhoto" to set albumList to name of albums whose type is regular album and name is not "Flagged" and name is not "Last Import"
set albumName to choose from list albumList with prompt "select an album"
if albumName is false then return
set albumName to item 1 of albumName
end if
try
tell application "Finder" to set theFiles to files of folder theFolder
repeat with oneFile in theFiles
tell application "iPhoto"
if albumName is missing value then
import from (oneFile as alias)
repeat while importing
delay 1
end repeat
else
import from (oneFile as alias) to album albumName
repeat while importing
delay 1
end repeat
end if
end tell
end repeat
tell application "Finder"
delete files of folder theFolder
end tell
on error e
display dialog "an error occured: " & e buttons {"Cancel"} default button 1
end try
.
set {button returned:b} to display dialog "Import Images to." buttons {"Cancel", "New Album.", "Album."} with title my_title
if b = "Album." then
tell application "iPhoto" to set albumList to name of albums whose type is regular album and name is not "Flagged" and name is not "Last Import"
set albumName to choose from list albumList with prompt "select an album"
if albumName is false then return
set albumName to item 1 of albumName
else if b is "New Album." then
set {text returned:albumName} to display dialog "Enter Album Name" default answer ""
end if
try
tell application "Finder" to set theFiles to files of folder theFolder
tell application "iPhoto" to if not (exists album albumName) then new album name albumName
repeat with oneFile in theFiles
.
Thank you so much, this is exactly what I needed.
London
set theFolder to ((path to desktop as text) & "To iPhoto:")
set albumName to missing value
set my_title to "iPhoto Import from Folder"
set {button returned:b} to display dialog "Import Images to." buttons {"Cancel", "New Album.", "Album."} with title my_title
if b = "Album." then
tell application "iPhoto" to set albumList to name of albums whose type is regular album and name is not "Flagged" and name is not "Last Import"
set albumName to choose from list albumList with prompt "select an album"
if albumName is false then return
set albumName to item 1 of albumName
else if b is "New Album." then
set {text returned:albumName} to display dialog "Enter Album Name" default answer ""
end if
try
tell application "Finder" to set theFiles to files of folder theFolder
tell application "iPhoto" to if not (exists album albumName) then new album name albumName
repeat with oneFile in theFiles
tell application "iPhoto"
if albumName is missing value then
import from (oneFile as alias)
repeat while importing
delay 1
end repeat
else
import from (oneFile as alias) to album albumName
repeat while importing
delay 1
end repeat
end if
end tell
end repeat
tell application "Finder"
delete files of folder theFolder
end tell
on error e
display dialog "an error occured: " & e buttons {"Cancel"} default button 1
end try