Very new to Applescript and need some help

I have never used Applescript before and I have a project I am not even sure is possible.

I am a photographer and when I get my film scanned (yes I still use film) and get the files back I have to convert them all to a PSD file with certain adjustment layers on them and delete the original jpeg.

I want to write a script that does the following:
-Accepts a dropped folder OR set of files
-Opens the first file in Photoshop
-Adds a levels layer, curves layer, and color balance layer OR runs a custom PS action I have set up OR sends a key code to PS to make that action run.
-Saves the file to the same location as the file it opened (not imperative to save in that location, but it would be nice) OR creates a new folder on the desktop and saves them there
-Closes the file
-Deletes the original file
-Opens the next file and repeats

Is this even possible? Or something close? Where should I look to start learning how to do this?

Absolutely anything is possible with AppleScript!

If you need help with scripting Photoshop, drag Photoshop’s icon (not the Dock icon if you have one!) onto Script Editor’s icon (or AppleScript Editor in Snow Leopard/Lion). There you will find documentation on how to script Photoshop. (I don’t actually use Photoshop, so I don’t know whether or not it supports AppleScript.) If there’s no dictionary, there are alternate methods, so don’t fret!

Well, almost anything is possible :wink:

The script you’re asking for is almost certainly doable, and Photoshop is highly scriptable. But in my opinion you’ve chosen one hell of a challenge if this is your first real script. Personally I’m a little overwhelmed by the amount of scripting commands available in Photoshop, and so far I’ve been able to use Aperture for my image scripting needs.
All I’m saying is don’t beat yourself up if you can’t figure out how to bend Photoshop to your will. If it’s too big a mouthful, start simple and learn how to juggle image files around while modifying them with the Image Events suite.
Good luck buddy.

Hi there,

Over the years I’ve used batch processing quite a few times in Photoshop and it’s saved hours and hours.
Before you set off down the AS route can’t your process be done using batch processing?

I quickly knocked up an Action to add different Adjustment Layers to an image and then re-save it.
I then used the Batch option to run the Action on a folder of test images.

File > Automate > Batch

Is the process something more complex?

Regards,

Nick

That is actually what I have been doing. THe issue is if I shoot a wedding and I have 600 image sto process, I have to open them all up, or open them in large chunks and the processing goes fine at first but the longer it runs the slower it goes. And in a few cases it has crashed before I was able to save the files. So I want a process that opens them up one image at a time and process them all in one shot so I dont have to monitor it.

Hi

This is by no means the full solution as everybody’s situation is unique but its a step in the right direction for you i hope and you can build from it.

on open thefiles
	repeat with theFile in thefiles
		tell application "Finder" to set y to container of theFile as string
		tell application "Adobe Photoshop CS5"
			open theFile
			set display dialogs to never
			set thisdoc to current document
			tell thisdoc
				do action "Sepia Toning (layer)" from "Default Actions" -- change to your action
				set myoptions to {class:EPS save options, encoding:maximum quality JPEG, preview type:JPEG Mac OS}
				save thisdoc in y as Photoshop EPS with options myoptions appending lowercase extension without copying
			end tell
			close document 1 saving no
		end tell
	end repeat
end open

OK, so I have a start, but I am running into problems.

I have it ste to choose a destination folder at the beginning, but I can’t get the selected destination to be used when I try to save my file. And I am too new to this to even know what questions to ask. Any help on what and more importantly why I am having the trouble would be great.

Here is the code:

on open droppedFiles
set destinationFolder to choose folder with prompt “Where you wanna go?”
repeat with anItem in droppedFiles
tell application “Adobe Photoshop CS5”
open anItem
set thisdoc to current document
tell thisdoc
do action “Adjustments” from “My Actions”
save thisdoc in destinationFolder as Photoshop format
end tell
close thisdoc saving no
end tell
end repeat
end open

Also, I just tried changing the Photohop save command to save to a specific location (Users:David:Desktop:Test) and it gave me an error when it ran: “File/Folder expected”. What exactly does that mean?

OK, so i am getting closer.

The code below gives me an error saying “The variable destinationFolder is not defined.”
But I did define it. Any ideas?

on open droppedFiles
set destinationFolder to choose folder with prompt “Where you wanna go?”
display dialog destintionFolder
repeat with anItem in droppedFiles
tell application “Adobe Photoshop CS5”
open anItem
set thisdoc to current document
tell thisdoc
save in destinationFolder
end tell
end tell
end repeat
end open

HI,

please read the error message carefully.
The variable destinationFolder is indeed defined, but not destintionFolder in the display dialog line

as far as I know Photoshop expects the full (HFS) path as parameter of the save command


on open droppedFiles
	set destinationFolder to (choose folder with prompt "Where you wanna go?") as text
	display dialog destinationFolder
	repeat with anItem in droppedFiles
		tell application "Adobe Photoshop CS3"
			open anItem
			set thisdoc to current document
			tell thisdoc
				save in destinationFolder & its name
			end tell
		end tell
	end repeat
end open

IT WORKS!

So, because I am so new would you be kind enough to explain what the “as text” does in this scenario?

Thank you so much, by the way.

David

choose folder return an alias specifier, which is an object.
the as text coercion converts the alias specifier to a string path.
For example display dialog accepts only text