Monday, November 20, 2017

#1 2002-02-25 03:21:55 pm

T.J. Mahaffey
Administrator
From:: Arkansas, USA
Registered: 2002-11-20
Posts: 238
Website

Put Photoshop in a Headlock

I've always had a bit of an axe to grind with Adobe over their near-complete lack of support for AppleScript under Photoshop. And I'm not sure that'll ever change, or at least not because of anything I'll say in this article.

However, there are two ways to overcome Photoshop's deaf and dumb attitude toward our favorite scripting language. The first is to buy Main Event Software's PhotoScripter product which makes Photoshop 'AppleScript-aware'.

The second is to hijack Photoshop's built-in automation routines, called 'actions'. Lucky for you and me, although PhotoShop snubs AppleScript for the most part, it does have two commands in its paltry dictionary: 'open' and 'do script'. That's two commands enough to get into trouble. Let's get started, shall we?

I'm going to show you how to use a tiny bit of AppleScript to make Photoshop do your imaging grunt work.

First, open a photo and choose 'New Action' from the Actions palette.

new_action_pal.gif


Next, you'll be prompted to name your action. Give it a name, preferably one that makes sense and relates to what the action will do. In my case, I'm creating an action which sets resolution of my photo to 72 dpi. Hence the name 'setTo72dpi'.

name_action_before.gif
New Action


name_action_after.gif
New Action [Named]


Ok, now perform the commands you'd like to apply to your photo (and images in the future). In this case, I'll choose 'Image Size' from the 'Image' menu and enter 72 in the resolution field. Then, "OK".

change_res.gif


Lastly, I'll choose 'Save" from the 'File' menu.

It also doesn't hurt to check your action to be sure all your desired steps are present. In the screenshot below, I can verify that my resolution change, the save command as well as the close command are all present within my new action.

check_action.gif


Now, click the 'Stop' button at the bottom of the actions pallette. I have now recorded my action.

If I wanted the images processed by my soon-to-come droplet to also close after the save portion, I'd be sure and click the close button on this image before I stop recording. Otherwise, all original images processed with this action will remain open within Photoshop. A bit messy for my taste.

Now the fun part. AppleScript!

Open the Script Editor (or editor of choice, mine is Script Debugger) and enter the 'on open' handler like so:

script_edit1.gif


Next, let's plug in a repeat loop. We'll naturally want this droplet to process multiple images. Otherwise, what's the point, right? A couple of notes about the repeat loop.

I've chosen 'e' as our one-image variable and 'theFiles' as our list variable. Don't let this throw you. When we phrase this command, AppleScript assumes that a reference to ONE FILE will come after 'with' and a reference to the whole list of files we drop will come after 'in'. You can choose any variables you like. I've recently warmed up to single-letter variables in this context because they imply a single item. (We could have used 'winnie' and 'thePooh' for all it matters. Just use what makes sense to you.)

Don't forget to close your statements with 'end'!

script_edit2.gif


Next, we'll plug in our tell block which brings Photoshop to attention. (If you would like Photoshop to do it's dance in the foreground, include the "activate" command before step 9. Otherwise, the magic happens in the background.)

script_edit3.gif


Now the open command followed by our single-file variable, 'e'. Meaning, open the first file.

script_edit4.gif


Finally, the 'do script' command. This is followed by the name of our action. BE SURE to include the action's name exactly as it appears in your Photoshop actions pallette!

script_edit5.gif


Press 'Enter' or click the 'Check Syntax' button to compile and then save your script, preferably to the desktop for now. Choose 'Classic' applet from the popup menu and give your script a name. Again, choose a name that makes sense. If "Dragon Monkey" makes sense, that's your business, I suppose. <grin> Be sure to choose 'Never Show Startup Screen' and DON'T check 'Stay Open'. These are the default settings and most of us will keep them that way.

save_script.gif


There you have it! An AppleScript droplet which sets the resolution of your images to 72 dpi, all ready for the web!

droplet_icon.gif


Footnote: As of today, Adobe has announced Photoshop 7 which introduces full scriptability. Glory day! However, if you're like me, you may not be ready to plunk down the dough for a big upgrade. So, in the meantime, get that Script Editor crackin' and record those actions!


T.J.
tj@tjmahaffey.com


Filed under: Photoshop,, Mahaffey

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)