Help with passing files/photos into a script

Hi everybody,

I’m by no means a programmer, and my experience with AppleScript is a bit limited, but I’d appreciate any help!!

I’m writing an Export Action script for Adobe Lightroom that (after Lightroom exports the photos to a folder) opens iPhoto Library Manager, selects the correct iPhoto library, imports the photos into an album, and deletes the folder. It runs fine from within the Script Editor, but when I try to run it from Lightroom, it aborts. I believe Lightroom is trying to pass the exported photos to the script, and the script doesn’t know what to do with the input. Is there a way to tell the script to accept the files, but to perform other actions before using the photos? I’m stuck.

Again, I’m not a programmer, and I’m sure this is poorly written, but here’s my script:


global libCount
set quitter to 0

tell application "iPhoto Library Manager"
	activate
	
	--count the number of libraries, find the "Projects" library, and select it:
	
	set libCount to (count libraries)
	
	if name of library libCount is "Projects" then
		set current of library libCount to true
	else
		set counter to 1
		repeat until (quitter = 1)
			if name of library (libCount - counter) is "Projects" then
				set current of library (libCount - counter) to true
				set quitter to 1
			else
				counter + 1
				set quitter to 0
			end if
		end repeat
	end if
end tell

--import photos:
tell application "iPhoto"
	activate
	new album name "Imported from Lightroom"
	import from "/Users/gaswirth/Desktop/Export/" to album "Imported from Lightroom"
end tell

tell application "Finder" to move folder "Users:gaswirth:Desktop:Export" of startup disk to the trash

Thanks for the help!!

Hi,

try this:

set ExportFolder to ((path to desktop as Unicode text) & "Export:")

tell application "iPhoto Library Manager"
	activate
	set current of 1st library whose name is "Projects" to true
	-- relaunch iPhoto
	tell application "System Events" to tell process "iPhoto Library Manager" to keystroke "o" using command down
end tell

--import photos:
tell application "iPhoto"
	activate
	new album name "Imported from Lightroom"
	import from ExportFolder to album "Imported from Lightroom"
end tell

tell application "Finder" to delete folder ExportFolder

Hi Stefan,

The script still aborts right after it’s executed from Lightroom–it’s icon pops up in the Dock, as though it’s going to run, and then quits a second afterward, having done nothing (same thing that happened with mine). I think when Lightroom finishes exporting and is told to execute an Export Action (be it an application, script, droplet, etc), it passes the exported images to the action. Could the problem be that our scripts don’t handle the files Lightroom is trying to pass to it?

Also, when I try to run yours from within Script Editor, iPhoto and Script Editor both give an error message saying it can’t find the folder, though the path is correct, and exists.

Thanks again for the help! Very much appreciated!

Hi,

unfortunately I don’t own Lightroom so I have no idea how it works.

The dictionary of iPhoto is lying:
the command import expects an alias, not an Unicode text path, so change this line

... import from (ExportFolder as alias) to album "Imported from Lightroom" ...