Jump to content

Help with Sleep ... Until Photoshop has finished an action


Go to solution Solved by Gianni,

Recommended Posts

Hello Guys,

I'm relativley new to Auto IT.

I'm currently writing a script for an complete automation process of a big Photoshop action.

It needs some preparation with renaming files, moving them to specific folders before the PS action can start...

I've scripted all these tasks already, and it works fine.

I also scripted the launching of the action within Photoshop and this works also.

BUT:

The script has to wait until Photoshop finished executing the action, which can take around 1-2 hours depending on the PC its running on and the number of files edited.

In this action, Photoshop opens up an image, makes a specific edit to it, saves and closes the image and then opens up the next one to do the same again until it has edited all the files in the source folder.

I've tried to use the "do sleep ... until"-loop to get the script to pause, using window titles as indicator, as PS changes its title from "Adobe Photoshop CS5.1 Extended" when its idle to " 'NameOfTheImageOpenend.jpg' at 16,7% (RGB/8)" when something is opened.

The problem is, when PS closes the first image and opens the second one, the window title changes to "Adobe Photoshop CS5.1 Extended" in between these tasks, as it is idle for a split second in this state.

So the loop ends after the first image was edited and the script continues, while PS has still around 300 files to edit.

Is there any way I can tell auto it to check if the Window title stays "Adobe Photoshop CS5.1 Extended" for like 2-3 seconds and then continue the script (end the loop)?

That would be excatly what I need.

I've already tried using ControlCommand (... "IsVisible") on a control that only shows if Photoshop is idle,

checking if the log file in which PS saves errors occurred while an action exists

(doesn't work because the file is created after 2-3 Seconds after the action started and not at the ending of the action :( )

and reading the log file for "End of Action" which PS writes in the file when it has finished.

(doesn't work because I don't know exactly how to do it in combination with the "do sleep ... until" loop, as the file has to be read after PS wrote "End of Action" into it -> after the action finished)

Folks, I really hope you can help me... I'm so desperate about this problem :D

Here is my current script part contaning this problem with PS:

Run("C:\Program Files\Adobe\Adobe Photoshop CS5.1 (64 Bit)\Photoshop.exe")
WinWaitActive ("Adobe Photoshop CS5.1 Extended")
sleep(1000)
Send("{alt}")
Send("t")
Send("u")
Send("s")
WinWaitActive ("Stapelverarbeitung")
WinActivate("Stapelverarbeitung")
ControlClick("Stapelverarbeitung", "","[CLASS:ComboBox; INSTANCE:1]")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:1]", "{DOWN 6}")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:1]", "{ENTER}")
sleep(200)
ControlClick("Stapelverarbeitung", "","[CLASS:ComboBox; INSTANCE:2]")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:2]", "{DOWN 4}")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:2]", "{ENTER}")
ControlClick("Stapelverarbeitung", "","[CLASS:Button; INSTANCE:1]")
WinWaitActive ("Ordner suchen")
Send("{HOME}")
Send("{ENTER}")
Sleep(200)
ControlClick("Stapelverarbeitung", "","[CLASS:Button; INSTANCE:1]")
WinWaitActive ("Ordner suchen")
Send("c")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("s")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("{v 3}")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("c")
Sleep(200)
ControlClick("Ordner suchen", "", "[CLASS:Button; INSTANCE:1]")
WinActivate("Stapelverarbeitung")
ControlClick("Stapelverarbeitung", "","[CLASS:Button; INSTANCE:12]")
sleep(500)

Local $psvarx = FileRead ("C:\SCRIPT\Fehlerlog.txt")
Local $psvarw = ControlCommand("", "Korrekturen","[CLASS:OWL.Dock; INSTANCE:5]", "IsVisible")
While $psvarw = 0 And StringInStr($psvarx, "Stapelende") = 0

sleep (1000)

WEnd

#cs
doesn't work
Do
   $psvar5 = WinGetTitle ("")
   Sleep (1400)
Until $psvar5 = "Adobe Photoshop CS5.1 Extended"
#ce

#cs
doesn't work
Do
   $psvar6 = ControlCommand("Adobe Photoshop CS5.1 Extended", "","[CLASS:OWL.Dock; INSTANCE:5]", "IsVisible")
   $psvar8 = ControlCommand("Adobe Photoshop CS5.1 Extended", "","[CLASS:PSViewC; INSTANCE:31]", "IsVisible")
   Sleep (10000)

Until $psvar6 = 1 and $psvar8 = 0
#ce


WinActivate("Adobe Photoshop CS5.1 Extended")
sleep(500)
Send("{alt}")
Send("t")
Send("u")
Send("s")
WinWaitActive ("Stapelverarbeitung")
WinActivate("Stapelverarbeitung")
ControlClick("Stapelverarbeitung", "","[CLASS:ComboBox; INSTANCE:1]")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:1]", "{DOWN 6}")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:1]", "{ENTER}")
sleep(200)
ControlClick("Stapelverarbeitung", "","[CLASS:ComboBox; INSTANCE:2]")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:2]", "{DOWN 4}")
ControlSend("Stapelverarbeitung", "", "[CLASS:ComboBox; INSTANCE:2]", "{ENTER}")
ControlClick("Stapelverarbeitung", "","[CLASS:Button; INSTANCE:1]")
WinWaitActive ("Ordner suchen")
Send("{HOME}")
Send("{ENTER}")
Sleep(200)
ControlClick("Stapelverarbeitung", "","[CLASS:Button; INSTANCE:1]")
WinWaitActive ("Ordner suchen")
Send("c")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("s")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("{v 3}")
Sleep(200)
Send("{RIGHT}")
Sleep(200)
Send("{c 2}")
Sleep(200)
ControlClick("Ordner suchen", "", "[CLASS:Button; INSTANCE:1]")
WinActivate("Stapelverarbeitung")
ControlClick("Stapelverarbeitung", "","[CLASS:Button; INSTANCE:12]")

Local $psvarx = FileRead ("C:\SCRIPT\Fehlerlog.txt")
Local $psvarw = ControlCommand("", "Korrekturen","[CLASS:OWL.Dock; INSTANCE:5]", "IsVisible")
While $psvarw = 0 And StringInStr($psvarx, "Stapelende") = 0

sleep (1000)

WEnd

$psvar2 = WinGetProcess("Adobe Photoshop CS5.1 Extended")
ProcessClose($psvar2)
Link to comment
Share on other sites

how about this: assuming the processing changes the timestamp of the image file,

before your AutoIt script calls Photoshop action: remember the latest timestamp of any of the files in the folder.

while Photoshop action is running: periodically, check for the earliest timestamp of any of the files in the folder, and if this earliest is later than the remembered latest, then all images have been processed, and you're done.

check out FileListToArray() and FileGetTime() in the help.

EDIT: P.S. you are aware of "Photoshop actions", right?

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • Solution

Hi xXxnoobiexXx
if I understand well what you mean, than this snippet could do (not tested)

Do
    Do
        Sleep(500) ; first check, every half second
        $psvar5 = WinGetTitle("[active]"); returns the active window's title
    Until $psvar5 = "Adobe Photoshop CS5.1 Extended" ; when title is "Adobe Photoshop CS5.1 Extended" go ahead
    Sleep(1500) ; wait 1 second and half <-- calibrate this according to your valuations
    ;
    $psvar5 = WinGetTitle("[active]"); get again the active window's title
    ; If after above delay the title is still "Adobe Photoshop CS5.1 Extended"
    ; we desume that photoshop is idle (because whole job is finished)
Until $psvar5 = "Adobe Photoshop CS5.1 Extended"

use the above code instead of this in your listing:

#cs
doesn't work
Do
   $psvar5 = WinGetTitle ("")
   Sleep (1400)
Until $psvar5 = "Adobe Photoshop CS5.1 Extended"
#ce
Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hi Chimp,

Thank you very very much for your answer!!!

It works!!! I'm so happy right now :thumbsup: You made my day!

The whole time I thought of something like this, but my knowledge didn't include "a Do.. until-Loop within a do ... until- loop".

Thats so simple, I know, but I simply didn't thought of it.

@orbs:

Thanks for your answer a well, I also messed around with your idea a bit, but it wasn't exactly what I needed. Because sometimes the action edits around 200 files, sometimes around 300, depending on its use case. And with this method I only found ways where the script has to declare the exact number of files in source folder. My script needs to be "universal" you know...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...