Applescript iPhoto Assign Keyword - cannot assign

I’m just getting back into scripting and I’m writing a few basic scripts to learn. The problem is that I am trying to do something that every other script example I’ve seen does easily, but mine doesn’t work? I’m hoping someone can pickup what I’m doing wrong.

My script currently allows a user to select a photo. This photo is then imported into iPhoto and a keyword is assigned. Note that I have added this keyword into iPhoto and assigned a few manually to make sure it works. I’ve even tried assigning a keyword of Birthday and that doesn’t work either?

set theFiles to choose file with prompt “select pictures to import” with multiple selections allowed
repeat with oneFile in theFiles
tell application “Finder” to set {theName} to {name} of oneFile

tell application "iPhoto"
	try
		import from oneFile
		assign keyword string "New"
		set thePhoto to (1st photo of last rolls album whose image filename is theName)
	end try
end tell

end repeat

Any help would be much appreciated.

Hi Adam,

The dictionary says assign keyword to the currently selected photo. Is the photo selected when imported?

gl,
kel

Hi,

Also, the dictionary says that the path to the file should be text:

I think it’s something like this:

set new_photo to choose file
set new_photo_pp to POSIX path of new_photo
tell application "iPhoto"
	activate
	import photo from new_photo_pp
end tell

Just trying to go through the steps.

gl,
kel

This works for one imported photo:

set new_photo to choose file
set new_photo_pp to POSIX path of new_photo
tell application "iPhoto"
	activate
	import photo from new_photo_pp
	set import_album to last import album
	set imported_photo to first photo of import_album
	select imported_photo
	assign keyword string "New"
end tell

Note that the keyword “New” must already exist.

gl,
kel

Also, in Mavericks, last rolls album is obsolete:

gl,
kel

Hi,

you can import multiple files at the same time with the import command.
It’s not necessary to coerce the paths, iPhoto accepts also alias specifiers
To assign the keyword you have to select the photos in iPhoto programmatically


set theFiles to choose file with prompt "select pictures to import" with multiple selections allowed
tell application "iPhoto"
	import from theFiles
	select photos of last import album
	assign keyword string "New"
end tell