Hi Guys,
This is my first post here, so go easy on me
Anyways, I just finished creating an installer that basically just installs a folder of files onto the user’s desktop. However, afterwords, the company wants me to pop up a dialog asking if the user wants one of the folders containing all photos to be imported automatically into iPhoto. I have a script that was written to do just this, but for some reason it is failing in multiple spots. The first spot it fails is at the beginning, I will attach that code snippet and hopefully you can give me some pointers as to what I am doing wrong, or if there’s an easier way to accomplish this. Also, I am running the latest version of iPhoto just to let you know.
The error I get is (which is due to the first 5 lines of code I believe), “Installer got an error: “Installation is almost complete. Would you like the images added to your iPhoto Library as albums? This is recommended.” doesn’t understand the display dialog message.”
Here’s the code:
set workout_list to {"PumpOne for Men"} -- WORKOUTS_LIST
tell application "Installer"
activate
display dialog "Installation is almost complete. Would you like the images added to your iPhoto Library as albums? This is recommended." buttons {"No", "Yes"} default button 2
if the button returned of the result is "Yes" then
set i to 1
try
tell application "iPhoto" to quit
tell application "System Events"
repeat until not (process "iPhoto" exists)
delay 1
end repeat
end tell
repeat 5 times
tell application "iPhoto" to activate
tell application "System Events"
if process "iPhoto" exists then
exit repeat
end if
end tell
end repeat
on error
display dialog "The installer cannot create iPhoto albums because iPhoto is not in the Applications folder. The image folders have been copied to the desktop." buttons {"Ok"} default button 1
return -1
end try
set vLessSeven to "False"
tell application "iPhoto"
if (version as string) < "7" then --This section only executes if iPhoto has version less than 7
set vLessSeven to "True"
tell application "iPhoto" to select photo library album
tell application "System Events"
set frontmost of process "iPhoto" to true
tell process "iPhoto" to set film_roll to the value of attribute "AXMenuItemMarkChar" of menu item "Film Rolls" of menu 1 of menu bar item "View" of menu bar 1
end tell
end if
end tell
repeat count (workout_list) times
tell application "iPhoto"
if not (album (item i of workout_list) exists) then
new album name (item i of workout_list)
end if
select album (item i of workout_list)
tell application "System Events" to tell process "iPhoto" to (click menu item "by Title" of menu 1 of menu item "Sort Photos" of menu 1 of menu bar item "View" of menu bar 1)
end tell
set i to i + 1
end repeat
set i to 1
repeat count (workout_list) times
if (my import_iphoto(item i of workout_list) is not 0) then
repeat
tell application "Installer"
activate
display dialog "An error occurred during import. Try importing " & (item i of workout_list) & " album again?" buttons {"No", "Yes"} default button 2
if the button returned of the result is "No" then
exit repeat
else
if (my import_iphoto(item i of workout_list) is 0) then
exit repeat
end if
end if
end tell
end repeat
end if
tell application "iPhoto" to select album (item i of workout_list)
tell application "System Events" to tell process "iPhoto" to (click menu item "by Title" of menu 1 of menu item "Sort Photos" of menu 1 of menu bar item "View" of menu bar 1)
set i to i + 1
end repeat
end if
tell application "System Events"
delay 1
if (vLessSeven) = "True" then --This section only executes if iPhoto has version less than 7
if film_roll is not "" then
tell application "iPhoto" to select photo library album
tell process "iPhoto" to click menu item "Film Rolls" of menu 1 of menu bar item "View" of menu bar 1
else
tell application "iPhoto" to select photo library album
end if
end if
delay 1
try --try added since it might not find the appropriate album
if (vLessSeven) = "True" then
tell application "iPhoto" to select album (item (i - 1) of workout_list)
else
tell application "iPhoto" to select album "Events"
end if
on error
--do nothing
end try
set frontmost of process "Installer" to true
end tell
end tell
on import_iphoto(workout)
try
tell application "iPhoto"
activate
tell application "System Events" to tell process "iPhoto"
repeat until not (static text "Would you like to import them?" of window 1 exists)
delay 1
end repeat
repeat until not (window "Duplicate Photo" exists)
delay 1
end repeat
repeat until not (static text "Your photo library was not found. Do you want to find your iPhoto Library folder?" of window 1 exists) and not (window "New Photo Library" exists) and not (window "Open Photo Library" exists)
delay 1
end repeat
end tell
if not (album workout exists) then
new album name workout
end if
select album workout
tell application "System Events" to tell process "iPhoto" to (click menu item "by Title" of menu 1 of menu item "Sort Photos" of menu 1 of menu bar item "View" of menu bar 1)
set the_directory to (path to "root" from user domain) & "Desktop:PumpOne for Men:" & workout as string
remove every photo of album workout from photo library album
import from POSIX path of the_directory to album workout
tell application "System Events"
tell process "iPhoto"
repeat until not (progress indicator 1 of splitter group 1 of group 1 of window "iPhoto" exists)
delay 1
end repeat
repeat until not (sheet 1 of window "iPhoto" exists)
delay 1
end repeat
end tell
end tell
end tell
return 0
on error
return -1
end try
end import_iphoto
Just to reiterate, I don’t have much experience in AppleScript, but I do have a ton of experience coding and with other scripting languages, so I can kind of understand what is going on, but any clarification would also be helpful.
Any ideas why this is failing?
Model: Macbook Pro Unibody
Browser: Safari 530.18
Operating System: Mac OS X (10.5)