How to create your own Photoshop scripts
Bored of doing the same repetitive tasks in Photoshop? Then create a script to automate it. We show you how, so you can free up your time for creativity...
If you’ve used Photoshop for more than a few months you’ll have no doubt come across actions - little pockets of wonderment that allow us to be free of identical tasks that are essential, but eat into our quality creative time. Actions are great (check out our selection of must-have actions for Photoshop here), but they do have one serious limitation: they’re dumb, and can’t do anything more complicated than play back through the prescribed series of steps.
Thankfully, Adobe recognised this problem a long time ago, and added support for scripting to Photoshop and most of their other creative tools. Photoshop’s scripting engine allows you to write in Applescript, VBScript or JavaScript, and perform complex operations that would normally require human intervention.
So, what’s an example of something that a script can do that an action can’t? Well, take the very basic example of toggling a layer’s visibility on and off. An action can easily turn off the visibility of a layer (or turn it on), but it can’t toggle visibility intelligently. A script can determine the current visibility state of a given layer, then perform a different task according that state.
It’s this ability to make conditional decisions that sets scripts apart from actions, and makes them super-powerful. For some great examples of what you can do with scripts, see this list of the best free Photoshop scripts.
Naturally, creating scripts does require a little programming, but if you’re already familiar with JavaScript you’ll find it very easy to get started. To make it a little less painful, Adobe has thoughtfully created a scripting manual, along with some excellent sample scripts.
Versions of Photoshop
If you’re using a version of Photoshop earlier than CS5, the scripting guide is available in your Application > Photoshop > Scripting folder. If you’re using CS6, you’ll find that this isn’t installed by default - you’ll need to download it here. You can also find complete script reference guides at the same place.
Once you feel comfortable with scripting you’ll be able to automate many functions within Photoshop, whether it’s creating 1000 web images or automatically generating meta data with your copyright notifications.
Get top Black Friday deals sent straight to your inbox: Sign up now!
We curate the best offers on creative kit and give our expert recommendations to save you time this Black Friday. Upgrade your setup for less with Creative Bloq.
Action or Script?
When deciding whether a task requires an action or a script, the golden mantra to remember is that actions are great for performing identical tasks over and over again.
Scripts allow you to create a custom, conditional result which is ideal for similar but non-identical tasks.
Make your own script
Step 01
You can create your script in Textpad or Notepad. You'll find a full reference guide in the Photoshop install directory called 'Scripting Guide'. You’ll also find some sample scripts in this directory.
Using JavaScript as the scripting language (Photoshop also supports Visual Basic and AppleScript) will ensure your script works across both PCs and Macs. We’re going to create a script that just pops up a message to illustrate the point.
Step 02
Enter the following text into your text editor:
var docRef = app.activeDocument;
var dlg = new Window('dialog', 'My first script!',[100,100,480,250]);
dlg.btnPnl = dlg.add('panel', [25,15,365,125], 'Hello world!');
dlg.btnPnl.testBtn = dlg.btnPnl.add('button', [15,30,305,50], 'Finished', {name:'ok'});
dlg.btnPnl.testBtn.onClick = dobuild;
dlg.show();
function dobuild() {
alert("Congratulations - it all worked!");
dlg.close();
}
Save the document as testscript.jsx if you are using Photoshop CS2, or testscript.js if you are using Photoshop CS3 and above.
Step 03
In Photoshop, open a document you’re working on. Select File > Scripts > Browse and locate your script (or one of the sample scripts if you haven’t plucked up the courage to create your own yet).
All being well, your script will open and execute. If you’re using the sample script above, you’ll see a dialogue box appear with some text and a button.
Clicking on the button will simply pop-up a message, but you can have Photoshop perform all manner of tasks when the button is pressed. This is where the real power of scripting shows itself. Your scripts can do anything Photoshop can - apply filters, resize documents, show or hide layers, add adjustment layers as well as save and export documents.
Set up an event-based script
Scripts (and actions) can be executed automatically by Photoshop when a particular event fires. These events can include opening Photoshop, creating a new document, printing and many more. Event-based scripts are an ideal way to deal with common tasks you commonly perform time after time, based on the specific event. For example, you might want to edit the metadata for your file when you first create it. Using an event-based script, you can have the file info panel pop-up as soon as you create a new document.
Setting up an event-based script is really easy - follow our step-by-step guide below:
Step 01
Start by creating the script you’d like to execute, or have a look at some of the sample scripts Adobe has provided.
Step 02
Open the event-based scripts manager by choosing File > Scripts > Script Events Manager. Once the dialog box is open, check the Enable Events to Run Scripts/Actions checkbox.
Step 03
Select the event from the Photoshop Event drop-down list. If you can’t see the precise event you’d like to capture, check out the scripting reference guide for details on how to add your own events based on Photoshop’s internal event listeners.
Step 04
Choose your script, or select from one of the presets included in the drop-down list of scripts. If you’d rather run an action based on this event, choose the 'action' radio button instead and browse your list of available actions.
Step 05
Click the Done button to close the Script Events Manager, or the Add button if you’d like to add additional event-based scripts.
Words: Sam Hampton-Smith
Liked this? Read these!
- Adobe Photoshop CS6 hands-on review
- Free Photoshop brushes
- The best Photoshop plugins
Have you seen some great Photoshop scripts, or have you created your own worth sharing? Let us know in the comments below!
Thank you for reading 5 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1
The Creative Bloq team is made up of a group of design fans, and has changed and evolved since Creative Bloq began back in 2012. The current website team consists of eight full-time members of staff: Editor Georgia Coggan, Deputy Editor Rosie Hilder, Ecommerce Editor Beren Neale, Senior News Editor Daniel Piper, Editor, Digital Art and 3D Ian Dean, Tech Reviews Editor Erlingur Einarsson and Ecommerce Writer Beth Nicholls and Staff Writer Natalie Fear, as well as a roster of freelancers from around the world. The 3D World and ImagineFX magazine teams also pitch in, ensuring that content from 3D World and ImagineFX is represented on Creative Bloq.