Make a script into a folder action?

Hello all! I’ve been cruising these forums for a while, but I need some help. I looked around for it, and I’m too much of a n00b to use anything I found. Sorry, and thanks, in advance!

In a nutshell, this script takes a picture that is taken with Photo Booth, and watermarks it using iMagine Photo. I got the script working just fine on its own, but I need to make it into a folder action script, so that it watermarks the image that gets added to the folder /users/whatever/Picutres/Photo Booth/. The file will always be called “Photo 1.jpg” because I delete the original at the end of the code, and move the watermarked result to the desktop.

Here’s my code:

set waterMarkFile to alias "Macintosh HD:Users:demo:Desktop:pb:wm1.png"
set thisImage to alias "Macintosh HD:Users:demo:Pictures:Photo Booth:Photo 1.jpg"
set finalFile to "Macintosh HD:Users:demo:Desktop:Watermarked Image.jpg"
set amountToBlend to 90
tell application "iMagine Photo"
	-- import image and watermark and create a window to draw them to.
	set waterMarkImporter to import graphic waterMarkFile
	
	set thisImporter to import graphic thisImage
	
	set {x, y, xDim, yDim} to the natural bounds of thisImporter
	set thisDocument to make new window document with properties {dimensions:{xDim, yDim}}
	set the drawing destination of thisImporter to thisDocument
	set the drawing destination of waterMarkImporter to thisDocument
	draw thisImporter
	-- scaling and positioning code for the watermark
	set {x, y, xWDim, yWDim} to the natural bounds of waterMarkImporter
	set scaleX to xDim / xWDim
	set scaleY to yDim / yWDim
	set theTop to 0
	set theLeft to 0
	if scaleY is less than scaleX then
		set scaleX to scaleY
		set theLeft to ((xDim - (scaleX * xWDim)) / 2) as integer
	else
		set scaleY to scaleX
		set theTop to ((yDim - (scaleY * yWDim)) / 2) as integer
	end if
	set the scale of waterMarkImporter to {scaleX, scaleY}
	set the top left point of waterMarkImporter to {theLeft, theTop}
	set amountToBlend to (amountToBlend / 100) * 65535 as integer
	set blendOpColor to {amountToBlend, amountToBlend, amountToBlend}
	set the drawing mode of waterMarkImporter to {graphics mode:alpha blend, opcolor:blendOpColor}
	draw waterMarkImporter
	set export file location of thisDocument to finalFile
	export thisDocument
	close thisDocument
	close thisImporter
	close waterMarkImporter
	quit "iMagine Photo"
end tell


set filetodel to alias "Macintosh HD:Users:demo:Pictures:Photo Booth:Photo 1.jpg"
tell application "Finder"
	delete filetodel
end tell

tell application "Finder"
	empty the trash
end tell

Like I said… I’m a noob. Be gentle, and I hope someone can help. As it stands, I can’t attach it to a folder… Because I can’t get it to do the “add new items” thing.

Hi.

If you control click in your script document, a contextual menu appears. You’ll find this under Folder Actions Handlers.

on adding folder items to this_folder after receiving these_items
	-- insert actions here
end adding folder items to

Take a look at the different clauses and handlers. Selecting one will add it to your script.