Elements Village

How to use the forums


Go Back   Elements Village > Strut Your Stuff > Forum Member Tutorials

Reply
 
Thread Tools Display Modes
  #1  
Old November 4th, 2008, 06:22 AM
lemon_juice lemon_juice is offline
New Forum User
 
Join Date: Nov 2008
Posts: 7
Apply almost any action to a batch of images automatically in PSE

I would like to share a method of applying almost any action, filter, adjustment or a set of those to a large number of pictures automatically. We all know that full photoshop has a very handy action recorder that, combined with the batch processing tool, you can use to apply the same conversions to all images in a folder. I've always wanted to do something similar in Elements but the batch options are so limited that most of the time I don't find them useful for anything - there are freeware programs (eg. XnView) which can do a whole lot more than the Elements "Process Multiple Files". What I specifically wanted to do was apply a filter to all photos from my camera - for example Chromatic Aberration correction or noise reduction. Because I couldn't find any solution to this I began my own "research".

(BTW for those who wonder about CA correction there is a good free plugin at http://www.chromacute.com/ that works well with PSE 5 and later)

I found a very powerful free program for automating tasks in any Windows application called AutoHotkey: http://www.autohotkey.com/. With this program you can send any number of keystrokes to any program to accomplish a series of repetitive tasks. However, this program is not very easy for everyone because you need to write a special script for your task but once you have a script ready you can use it at any time. Fortunately the help file is quite extensive and with a bit of effort you can learn to write your own scripts. Here I will show you how to do it specifically for PSE - I used PSE 7 but it should work the same in earlier versions too.

First install AutoHotkey. It's not a program that you will run as a standalone application but rather invoke it by running a script. So you need to begin by writing a script for your task - you can use notepad or your favourite plain text editor. A script is a text file with the .ahk extension. When you double click on such a file in windows explorer AutoHotkey will start executing your script. I will present an example of a script that you can use right away and is quite flexible - it will apply any filter to a batch of jpg images by using the ctrl+F shortcut, which runs the last used filter. So let's begin by creating the script:

Code:
#NoEnv
SetWorkingDir %A_ScriptDir%

Loop *.jpg
{
    RunWait "C:\Program Files\Adobe\Photoshop Elements 7.0\PhotoshopElementsEditor.exe" "%A_LoopFileLongPath%"

    Gosub WaitToComplete
    SendInput ^f
    
    Loop
    {
        IfWinActive Save As
        {
            break
        }
        ifWinActive ahk_class pseeditor 
        {
            SendInput +^s
        }
        Sleep 500
    }
    Sleep 1500
    SendInput {enter}
    Sleep 1000
    SendInput {enter}
    WinWait ahk_class PSFloatC
    SendInput 12{enter}
    
    Gosub WaitToComplete
    SendInput ^w
    Sleep 500
}

ExitApp

WaitToComplete:
    Loop
    {
        IfWinExist New Layer ahk_class PSFloatC
        {
            WinActivate New Layer ahk_class PSFloatC
            break
        }
        ifWinActive ahk_class pseeditor
        {
            SendInput +^n
        }
        Sleep 500
    }
    
    SendInput {esc}
return

~esc::ExitApp
Copy & paste it to the notepad. Change the path to PSE after the RunWait command - this can be different depending on your system and PSE version. We need to invoke the PhotoshopElementsEditor.exe. Save the file as "Last Filter.ahk" to the same folder where you store the jpg files for conversion. Always work on copy of your images because this script will overwrite the original pictures! And you want to make sure you don't destroy your originals in case something goes wrong. Now start PSE, open or create any image, apply the filter of your choice and close the file without saving. We just want to make sure that we have the desired filter available under the ctrl+F shortcut. Then go to windows explorer and run the .ahk script and the conversion should start. AutoHotkey will simply press the keys as you would using the keyboard.

There are a few things to remember though:
* while the script is running you should not do anything else on the computer, don't touch the keyboard and don't click with your mouse
* make sure you turn off any background programs that might steal focus from PSE, for example by update alert pop-ups or low battery alerts- they may interrupt the script. The windows tray alerts are usually fine since they don't steal focus from the running application.
* if you really need to stop conversion for some reason just press the Esc key, which I programmed to terminate the script. Or, right click on the H icon in the tray and choose Exit. When the H disappears you will know the script has been stopped. If you switch to other programs while the script is running you may send some unwanted keystrokes to them, which might have unexpected results (however any damage is very unlikely)

Now I will explain what each of these commands do in the script so that you can easily change it and adapt it to your needs. Everything after semicolon is a comment and is not executed by a script:

Code:
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
This was added by AutoHotkey new script so I leave it there.

Code:
Loop *.jpg
{
This starts to loop over all jpg files in the current folder.

Code:
RunWait "D:\Program Files\Adobe\Photoshop Elements 7.0\PhotoshopElementsEditor.exe" "%A_LoopFileLongPath%"
This opens the current image in PSE (first starts PSE - well it is running already so it doesn't have to do that - and then opens the image).

Code:
Gosub WaitToComplete
WaitToComplete is our function that will wait for the image to open - more about it later. Opening an image can take a varying amount of time and we want to make sure this has finished before we proceed.

Code:
SendInput ^f
We press ctrl+F (=apply the filter). This is the heart of our script - we can change it to anything else we like.

Code:
Loop
    {
        IfWinActive Save As;   when Save As window appear we break out of the loop
        {
            break
        }
        ifWinActive ahk_class pseeditor;   just for safety: we send keystrokes only if PSE is the active window
        {
            SendInput +^s;   press shift+ctrl+S
        }
        Sleep 500;   waits 0.5 sec. (500 milliseconds)
    }
Here we press ctrl+shift+S every half a second until the Save As window appears. This is to ensure that the filter has done its job before we continue pressing keys.

Code:
Sleep 1500;    wait 1.5 sec.
    SendInput {enter};   press Enter (file overwrite confirmation window opens)
    Sleep 1000;   wait 1 sec.
    SendInput {enter};   press Enter (=we press 'Yes')
    WinWait ahk_class PSFloatC;   we wait until a subwindow of PSE opens, in this case it's the JPEG Options window
    SendInput 12{enter};    we type 12 in as the quality number (=highest quality) and press Enter
    
    Gosub WaitToComplete;    wait for the save to complete
    SendInput ^w;    press ctrl+w (=close the image window)
    Sleep 500;    wait half a second to make sure PSE had the time to close the image and we can procees to another one
};    end of image loop section

ExitApp;   exit the script when conversion is complete
And now our function whose purpose is to wait for any action to complete:

Code:
WaitToComplete:
    Loop
    {
        IfWinExist New Layer ahk_class PSFloatC
        {
            WinActivate New Layer ahk_class PSFloatC
            break
        }
        ifWinActive ahk_class pseeditor
        {
            SendInput +^n
        }
        Sleep 500
    }
    
    SendInput {esc}
return
This is a trick I came up after not being able to find a more elegant solution - but it works very well! When PSE is busy doing something (eg. applying a filter) we press shift+ctrl+N every half a second in this loop. shift+ctrl+N is a shortcut for creating a new layer. Of course we don't want to do that but the trick is that when PSE is not busy anymore it will open a dialog window where you can enter the new layer's name. And our script can detect when this window opens and in this way we know when we can proceed. Pressing Esc closes the window.

And the last one:

Code:
~esc::ExitApp
This will simply register the Esc key to exit the script in case we need to (for example we have to use urgently another program on this computer). We can do the same by right clicking on the H icon in windows tray and selecting Exit.


So now it's easy to modify this script to perform any other action we want or even a series of actions on any number of files. Just change
SendInput ^f

to anything else. For example, this will evoke ChromaCute filter on my computer:

Code:
SendInput !t{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{down}{right}{enter}
Because it has no native shortcut key we need to reach it by arrow keys. !t = alt+t invokes the filter menu and then we go down to the desired filter. The number of keystrokes may depend on your setup so it's good to check it first. You can even enter parameters to filters or action, for example invoke Levels by ^l and use tabs and number keys to enter desired values. You may have to use the WaitToComplete function after each action if you have many of them. You can read how to specify keys after sendInput on this page: http://www.autohotkey.com/docs/commands/Send.htm
Reply With Quote
  #2  
Old November 4th, 2008, 06:31 AM
lemon_juice lemon_juice is offline
New Forum User
 
Join Date: Nov 2008
Posts: 7
continued...

Another example: you want to read tif files, apply some filters and save as jpeg. You need to use Loop *.tif instead of Loop *.jpg. And the Save As dialog window will now have the tif format chosen by default so we need to change it with keys (use the following code after the loop invoking the "Save As" window):
Code:
    Sleep 1500;  wait for Save As to appear
    SendInput {tab}j{enter};   choose the JPEG format for saving
    WinWait ahk_class PSFloatC;   wait for JPEG Options to appear
    SendInput 12{enter};   type in the quality and press Enter
And make sure there are no jpg images in your folder since they may cause PSE to invoke the file overwrite window and you would need to modify the script for that.

And that's all that is required to run almost any action on a bunch of files in PSE. I'm happy that I have finally managed to find a method - by trial and error I have refined the script to run reliably, however I can't be sure if it will run well for everyone without modifications - I suppose it will for most people. I chose the Sleep times like these so that the script will not halt if the computer runs slower, sometimes if you were using other memory intensive applications before and switched back to PSE then things like opening the Save As window can take much slower on the first and second run. These times are always fine on my old Athlox XP 3000 machine, if your computer is slow you may need to increase the times in case the script halts.

Enjoy!

PS. It's a Windows only solution, but there probably is a Mac equivalent of AutoHotkey so someone might adapt this method for Macs as well.
Reply With Quote
  #3  
Old November 4th, 2008, 09:21 AM
Michel B Michel B is offline
Known Forum User
 
Join Date: Jun 2007
Location: France, Paris
Posts: 589
Hi, Lemon-juice!
Thanks for sharing your efforts to find a way of batch processing in PSE. I must say I have not yet tested it, but it looks this can be of some help for those having some experience in programing...
I have tested the ChromAcute plug-in, and it gave good results on a test file with chromatic aberration. I'll test it with other type of purple fringing.
Reply With Quote
  #4  
Old November 4th, 2008, 01:58 PM
Diana's Avatar
Diana Diana is offline
Senior Contributor
 
Join Date: Sep 2005
Location: Mid-Michigan, USA
Posts: 6,111
Images: 14
Thanks, Lemon Juice, for figuring this out and taking the time to write such an in-depth tutorial. I will print this out and try it out when I get the time.

Diana
__________________
My PET Gallery
My Village Gallery

Happiness is not having what you want, but wanting what you have.

~ Canon Rebel XTi ~ EF70-200 f/4 ~ EF85 f/1.8 ~ EF24-70 f/2.8 ~ EF 24-105 f4 L IS ~ EF 50mm f/1.8 II ~ WinXP, Vista & Windows 7 ~ PSE 7 & 8 ~ CS3 ~ Pro Show Producer ~ Corel Painter X ~ Printers: Canon Pixma Pro9500 Mark II, HP Deskjet 882C, HP LaserJet 1200 ~
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to burn dvd so that it repeats automatically Gordon Macgregor Elements for Beginners 2 January 21st, 2008 07:08 AM
PE resizing images automatically when editing. CivicMan Photoshop Elements 6/7/8 Questions and Answers 16 July 15th, 2007 08:12 PM
Automatically Copying? wacom3 General Elements Discussion 1 April 2nd, 2006 02:14 PM
I want to post photos that change automatically. Rosiegirl General Elements Discussion 14 February 20th, 2006 12:25 PM
Batch processing images for the web Dean Roberts General Elements Discussion 1 November 17th, 2004 01:33 AM


All times are GMT -5. The time now is 04:01 PM.


Powered by vBulletin
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.