Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Set photo titles to picture capture date in iPhoto Apps
The titles iPhoto chooses for just-added photos is the annoying "IMG_nnnn" serial number from the camera. This AppleScript simply takes the date of the photo (EXIF info that iPhoto knows very well) and uses it as the photo title. The format is: yyyy-mm-dd-hh.mm.ss, so it's a bit easier to read than the ISO version, but also easily sortable.

Here's the code:
tell application "iPhoto"
  --  activate -- bring iPhoto back to front
  copy (my selected_images()) to these_images
  
  if these_images is {} then error "Please select some images before using this script."
  set thename to ""
  set thepaths to ""
  set thedates to ""
  repeat with i from 1 to the count of these_images
    set this_image to item i of these_images
    
    --set this_file to the image path of this_image    
    set thename to thename & ", " & the title of this_image
    --set thepaths to thepaths & the image path of this_image & ", "
    set thedate to the date of this_image
    
    set theyear to the year of thedate
    set themonth to my format(the month of thedate as number)
    set theday to my format(the day of thedate)
    set theseconds to my format(the seconds of thedate)
    set themins to my format(the minutes of thedate)
    set thehours to my format(the hours of thedate)
    
    set thetitle to theyear & "-" & themonth & "-" & ¬
      theday & "-" & thehours & "." & themins & "." & theseconds
    
    --set thedates to thedates & thetitle & ", "
    set the title of the item i of these_images to thetitle as string
    
  end repeat
  
end tell

on selected_images()
  tell application "iPhoto"
    try
      set these_items to the selection
      if the class of item 1 of these_items is album then error
      return these_items
    on error
      return {}
    end try
  end tell
end selected_images

on format(thenumber)
  if (thenumber as number) < 10 then
    set res to "0" & (thenumber as string)
  else
    set res to thenumber as string
  end if
  return res
end format
Copy and paste the above in AppleScript Editor, and save it as a Script named 'Rename Photos' (or whatever) in /Library » Scripts » Applications » iPhoto (create any of those folders as required). Make sure the AppleScript menu icon is visible (in AppleScript Editor's prefs in 10.6; in AppleScript Utility in 10.5), then switch to iPhoto. Select some photos in iPhoto from the Events or Photos section, then select the saved script from the AppleScript menu and ... voila ... the photo titles will change to their respective capture dates.

[robg adds: This worked as described in both 10.5 and 10.6. I modified the save path in the hint to include the Applications sub-folder, which forces the script to the top-level of the AppleScript menu. If you'd rather have it in an iPhoto sub-menu, save it into an iPhoto folder directly in the Scripts folder.]
    •    
  • Currently 3.17 / 5
  You rated: 5 / 5 (18 votes cast)
 
[8,801 views]  

Set photo titles to picture capture date in iPhoto | 17 comments | Create New Account
Click here to return to the 'Set photo titles to picture capture date in iPhoto' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Set photo titles to picture capture date in iPhoto
Authored by: homeshire on Mar 11, '10 08:07:36AM

I can't get the script to compile on 10.5 because of problems with "my format". So I sent it to my wife's laptop and compiled on 10.6.

Then I sent it back to my Leopard desktop, and I still can't get it to run. Curious, especially since robg claims to have gotten it to run on Leopard. It returns an error -1.

anybody with ideas. I'd really like to get this working.

thanks



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: mastige on Mar 11, '10 08:08:09AM
The script will not compile for me. This is the error:
A command name can’t go after this “my”.
The line that causes this is:
set themonth to my format(the month of thedate as number)


[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: robg on Mar 11, '10 03:28:24PM

I'm not sure what to say: it definitely compiled fine here on 10.5, and I just did it again by selecting the script as it appears in the actual hint, and it worked fine again.

-rob.



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: mastige on Mar 11, '10 04:39:51PM

If the script will not compile for you, then delete 'my format' from the five lines in which it appears. It works fine then. I had trouble finding documentation on 'format', so cannot explain the compile error.



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: homeshire on Mar 13, '10 03:56:31AM

this definitely did the trick on 10.5 .

happy to have it working, but now that I do, I should say that I agree with the comment that the batch change function within iPhoto is a more robust tool for doing this. the only advantage to this script (other than it's cool and works) is that I don't have to think of the date if that's what I truly want for the title. it automagically assigns to the photo as title.

thanks for the write-up.



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: marook on Mar 11, '10 08:23:56AM

Nice AppleScript, but why not just use iPhoto's build in Batch feature to set the Title to Date/Time ???
Does the same thing! ;-)

---
/Marook



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: woody97470 on Mar 11, '10 09:26:02AM

Yup, works well. thanX!



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: robleach on Mar 11, '10 09:27:31AM
Cool hint. I made a modification to make the date a little more readable, but still sortable (though I took out the seconds).
tell application "iPhoto"
	--  activate -- bring iPhoto back to front
	copy (my selected_images()) to these_images
	
	if these_images is {} then error "Please select some images before using this script."
	set thename to ""
	set thepaths to ""
	set thedates to ""
	repeat with i from 1 to the count of these_images
		set this_image to item i of these_images
		
		--set this_file to the image path of this_image    
		set thename to thename & ", " & the title of this_image
		--set thepaths to thepaths & the image path of this_image & ", "
		set thedate to the date of this_image
		
		set theyear to the year of thedate
		set themonth to my format(the month of thedate as number)
		set theday to my format(the day of thedate)
		set themins to my format(the minutes of thedate)
		set thehours to my format(the hours of thedate)
		set thetod to "am"
		if (thehours as number) > 12 then
			set thetod to "pm"
			set thehours to ((thehours as number) - 12)
		end if
		
		set thetitle to theyear & "/" & themonth & "/" & ¬
			theday & " at " & thehours & ":" & themins & thetod
		
		--set thedates to thedates & thetitle & ", "
		set the title of the item i of these_images to thetitle as string
		
	end repeat
	
end tell

on selected_images()
	tell application "iPhoto"
		try
			set these_items to the selection
			if the class of item 1 of these_items is album then error
			return these_items
		on error
			return {}
		end try
	end tell
end selected_images

on format(thenumber)
	if (thenumber as number) < 10 then
		set res to "0" & (thenumber as string)
	else
		set res to thenumber as string
	end if
	return res
end format


[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: scott721 on Mar 11, '10 09:40:22AM

I am getting a syntax error on the phrase "my format" in the line:

set themonth to my format (the month of thedate as number)

I presume the other lines with "my format" in them would generate the same error. Anyone else experiencing this or have a fix?



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: fracai on Mar 11, '10 09:49:37AM

You can also do this directly in iPhoto by using "Photos > Batch Change".

---
i am jack's amusing sig file



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: robleach on Mar 11, '10 12:25:09PM

Not for all intents and purposes though. Note the poster put the date in order of 4-digit year, month, day for sorting, but Batch Change does month, day & 2-digit year. Good to know though.



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: fracai on Mar 11, '10 03:46:15PM

You can use the short, abbreviated, and long date formats which are controlled by settings in the Language & Text Preference Pane. My "short" is set to use a 4 digit year for example.

---
i am jack's amusing sig file



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: barefootguru on Mar 11, '10 10:14:54AM

/Library is for all users on the Mac. If it's only yourself that needs the script then the Library folder in your home folder is more appropriate.



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: ihadmeavision on Mar 11, '10 05:58:22PM

I also use SuperDuper but haven't tried the scheduled backups for a while. The reason being that when logged out, Launchd would crash when trying to launch SuperDuper (I used to schedule backups at night, at the office, therefore the logging out). I'd come into the office in the morning to find one of the cores would be at 100% usage. I don't know if this has been fixed yet by Apple or SuperDuper (not sure who's at fault) but at least SuperDuper can backup everything as I'm working.

Edited on Mar 11, '10 06:00:52PM by ihadmeavision



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: bpwhistler on Mar 13, '10 02:22:35PM

Is there a way to rename pictures in Aperture to the capture date? I know I can rename them to many custom formats on import, but I have several thousand already in Aperture that I would like to rename.

Thanks



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: FlyBoy on Mar 13, '10 08:05:38PM

In Aperture 3, choose Batch Change under Metadata. One of the options is to choose image date, but you can also edit and create your own custom format.



[ Reply to This | # ]
Set photo titles to picture capture date in iPhoto
Authored by: bpwhistler on Mar 14, '10 07:08:17AM

Thanks very much.

I upgraded to A3 recently (hasn't it been recent for all of us!! LOL) and haven't had a chance to wade through everything yet. I'm glad Apple finally included a batch renaming feature.

I'm still waiting for an advanced duplicate finder...although Tidy Up! is working very well with A3 now and the developer is incredibly responsive to helping his customers.

Cheers



[ Reply to This | # ]