Go Back   The macosxhints Forums > OS X Help Requests > AppleScript



Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 05-17-2012, 01:12 AM   #1
anp12
Prospect
 
Join Date: Aug 2007
Posts: 47
retroactively import pictures into iphoto

I have no apple script experience.
I have recently decided to begin copying pictures upon import into iPhoto rather than not (option in iphoto preferences). Is there a way to make a script that will retroactively go through all the photos i have now in iphoto, find where they are on the computer, and reimport them with copying? I can't do it one by one for thousands of pictures!
thanks

Last edited by anp12; 05-17-2012 at 01:13 AM. Reason: no tags
anp12 is offline   Reply With Quote
Old 07-07-2012, 01:21 PM   #2
sojourner
Major Leaguer
 
Join Date: Apr 2010
Posts: 324
Can't write it for you right now, but it looks possible.

Assuming you have Lion, it looks like you'll need to
* select the photo
* use System Events to click the menu item which reveals where the file is on the computer
* save the file alias to a variable (ie: tell app "finder" to set aliasPhotoFile to (selection as alias)
* tell application "iPhoto" to import from aliasPhotoFile

and put that on a repeat loop.
__________________
see a problem; solve a problem.
sojourner is offline   Reply With Quote
Old 07-07-2012, 06:43 PM   #3
ganbustein
MVP
 
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,009
(In my opinion, scripting the GUI through System Events is an abomination. If you start clicking menu items and such-like, you're already on the path to madness. At best, you'll produce a brittle, buggy kludge that, even if it works once, is likely to break in the very nearfuture for no discernible reason. Other opinions may vary.)

Here's a script to build a folder of aliases to those photos in your current iPhoto selection whose originals are still not copied into the library. By all means, back up your iPhoto library before running it, and test it out on some small selections.

The script will prompt for a folder to put the aliases in. It's probably best if you give it a new empty folder, so the aliases it produces won't get commingled with whatever's already in the folder. (The script won't get confused, but you might be.)

You can then drag the folder or selected aliases into iPhoto to re-import the originals. Unfortunately, iPhoto will create duplicate photos when you do this, so as not to discard any edits that you may have already done, and also because it can't be sure you're really re-importing the same photo. It will detect the duplicates and ask what you want to do, but unless you agree to make duplicates nothing will happen.

I recommend that you work on one album/event at a time, to make the task of resolving duplicates manageable. (That's why the script always operates on your current selection, rather than addressing the entire library in one fell swoop.)

Code:
set libraryPath to (POSIX path of (path to pictures folder)) & "iPhoto Library/"
set aliasFolder to choose folder with prompt "Where should aliases to unimported photos be created?"
set aliasNumber to 0
set lostOriginals to 0

tell application "iPhoto"
	set sel to (get the selection)
	repeat with aPhoto in sel
		set itsPath to (image path of aPhoto)
		if itsPath does not start with libraryPath then
			my makeAliasFor(itsPath)
		end if
	end repeat
end tell
if lostOriginals is not 0 then
	display dialog "" & lostOriginals & " photos have already lost their originals." buttons {"Sigh"} default button 1
end if


on makeAliasFor(aPath)
	global aliasFolder, aliasNumber, lostOriginals
	try
		set anAlias to (POSIX file aPath as alias)
	on error
		set lostOriginals to lostOriginals + 1
		return
	end try
	
	repeat
		try
			set aliasNumber to aliasNumber + 1
			set aliasName to "Photo alias " & aliasNumber
			tell application "Finder"
				make new alias file at aliasFolder to anAlias with properties {name:aliasName}
				exit repeat
			end tell
		end try
	end repeat
end makeAliasFor
ganbustein is offline   Reply With Quote
Old 07-07-2012, 07:14 PM   #4
chabig
Hall of Famer
 
Join Date: Jan 2002
Posts: 2,933
It sounds like you have pictures in your iPhoto library that you want copies of in the Finder. The simplest way to do that is to export your entire iPhoto library to a folder. I would suggest creating a folder on your desktop. Then from iPhoto, select all of the pictures and drag them to your desktop folder, or choose File > Export.
chabig is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 09:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.