Sign in to follow this  
Followers 0
lisehu

Photoshop CS2

10 posts in this topic

Application: Adobe Photoshop CS2

I need to open the tif files using Photoshop and save them as PDF Presentation (File->Automate->PDF Presentation). I have 1000 tif files.

Qn1: Using AutoIT, how do I open the tif files in batches, say, select 50 tif files at one time then and save them as PDF Presentation? Once the 1st 50 tif files are saved, how does it open the next 50 tif files?

Qn2: How do I close the Adobe Photoshop application once all tif files are saved? I've tried but the application does not closed after I have save the files.

This is my code:

WinWaitClose("Save Adobe PDF")

;Close the Photoshop application

WinActivate("Adobe Photoshop")

Send("^q")

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I can think of 3 ways to do this:

You could make a script that copies the steps you would take if you did this manually.

You could possibly make a recorded action in photoshop doing most of the work, and automate that action, reducing the number of needed steps.

You could use the scripting interface in photoshop. The documentation for vbscript is easily applied to AutoIt.

Assisting you with this is a little difficult as lots of people won't have Photoshop installed and of the ones that do, a lot will have other versions. (the scripting option will hopefully be mostly version independent)

I'm currently installing CS5 to experiment with the scripting interface. (Only had it on OSX)

Meanwhile it might help if you could tell us how to identify the files you want to open and how you would manually export them.

(Are the files all in one folder? is there a logical order, are they in folders in groups of 50 already etc.)

It might also be useful if you could write down each action you take to manuaaly perform the task and then for each step check if there is a hotkey for the step and if the button/menu you click, can be identified using the AU3Info tool. (Ctrl+F6 in SciTE if you have the full package)

Edit: I'm pretty sure "Time remaining" should be going down when installing something. This thing is taking it's sweet time.

Edited by Tvern

Share this post


Link to post
Share on other sites

Thanks for your prompt response.

All tif files are reside in the same folder.

To open the tif files, this is my script

; Open File -> Automate -> PDF Presentation

Send("!F") ;Select menu File using shortcut key, Alt F

Send("U") ;Select menu Automate using shortcut key, U

Send("P") ;Select menu PDF Presentation using shortcut key, P

Send("!B") ;Browse for files

Send("C:\Folder\*.tif") ;Directory where the tif files are stored

Send("!O") ;Open only tif files

I can think of 3 ways to do this:

You could make a script that copies the steps you would take if you did this manually.

You could possibly make a recorded action in photoshop doing most of the work, and automate that action, reducing the number of needed steps.

You could use the scripting interface in photoshop. The documentation for vbscript is easily applied to AutoIt.

Assisting you with this is a little difficult as lots of people won't have Photoshop installed and of the ones that do, a lot will have other versions. (the scripting option will hopefully be mostly version independent)

I'm currently installing CS5 to experiment with the scripting interface. (Only had it on OSX)

Meanwhile it might help if you could tell us how to identify the files you want to open and how you would manually export them.

(Are the files all in one folder? is there a logical order, are they in folders in groups of 50 already etc.)

It might also be useful if you could write down each action you take to manuaaly perform the task and then for each step check if there is a hotkey for the step and if the button/menu you click, can be identified using the AU3Info tool. (Ctrl+F6 in SciTE if you have the full package)

Edit: I'm pretty sure "Time remaining" should be going down when installing something. This thing is taking it's sweet time.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

CS5 doesn't seem to have the "menu PDF Presentation" anymore and trying to use the function from the scripting interface gives me a COM error saying that the function is not available.

It might an error in my script, but perhaps this will work for CS2.

#include <array.au3>
#include <file.au3>

Global $aInFiles[50], $sOutFile, $n = 1, $l = 0
Global $sPath = FileSelectFolder("Select source folder", "", 2, @ScriptDir)
Global $aFiles = _FileListToArray($sPath,"*.tif",1)
If @error Then Exit
Global $oPhotoShop = ObjCreate("Photoshop.Application")
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

While $n < $aFiles[0]
    For $i = 0 To 49
        $aInFiles[$i] = $sPath & "\" & $aFiles[$n]
        If $n = $aFiles[0] Then
            ReDim $aInFiles[$i+1]
            ExitLoop
        EndIf
        $n += 1
    Next
    $l += 1
    $sOutFile = $sPath & "\OutFile" & $l & ".pdf"
    _ArrayDisplay($aInFiles,"Creating " & $sOutFile & " from the following files:")
    $oPhotoShop.MakePDFPresentation($aInFiles, $sOutFile)
WEnd
$oPhotoShop.Quit

Func MyErrFunc()
   ConsoleWrite("COM Error: " & Hex($oMyError.number,8) & @CRLF & "Description: " & $oMyError.description)
Endfunc

Edit: looks like the functionality was moved to adobe bridge, so it's no surprise I'm getting an error with that script. Hope it works for you.

Edited by Tvern

Share this post


Link to post
Share on other sites

Hi Tvern,

Thanks for the code. That is fast :unsure:

It mainly works except that it does not automatically click the OK button and Copy Selected button. Can you teach me how to do that?

1) The OK dialog box appear after FileSelectFolderpost-64620-0-87646500-1304493982_thumb.j

2) Creating C:\data\outfile.pdf from the following files: Window - how do the script select all files and then click the Copy Selected button?

Thank you in advance

CS5 doesn't seem to have the "menu PDF Presentation" anymore and trying to use the function from the scripting interface gives me a COM error saying that the function is not available.

It might an error in my script, but perhaps this will work for CS2.

#include <array.au3>
#include <file.au3>

Global $aInFiles[50], $sOutFile, $n = 1, $l = 0
Global $sPath = FileSelectFolder("Select source folder", "", 2, @ScriptDir)
Global $aFiles = _FileListToArray($sPath,"*.tif",1)
If @error Then Exit
Global $oPhotoShop = ObjCreate("Photoshop.Application")
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

While $n < $aFiles[0]
    For $i = 0 To 49
        $aInFiles[$i] = $sPath & "\" & $aFiles[$n]
        If $n = $aFiles[0] Then
            ReDim $aInFiles[$i+1]
            ExitLoop
        EndIf
        $n += 1
    Next
    $l += 1
    $sOutFile = $sPath & "\OutFile" & $l & ".pdf"
    _ArrayDisplay($aInFiles,"Creating " & $sOutFile & " from the following files:")
    $oPhotoShop.MakePDFPresentation($aInFiles, $sOutFile)
WEnd
$oPhotoShop.Quit

Func MyErrFunc()
   ConsoleWrite("COM Error: " & Hex($oMyError.number,8) & @CRLF & "Description: " & $oMyError.description)
Endfunc

Edit: looks like the functionality was moved to adobe bridge, so it's no surprise I'm getting an error with that script. Hope it works for you.

Share this post


Link to post
Share on other sites

Are you saying that it is making the PDF's, but you want to avoid FileSelectFolder and _ArrayDisplay? (You don't have to press "copy selected" btw, closing it is enough.)

Using the following example will do the entire process in the background, if you specify the right path on line 5.

#include <array.au3>
#include <file.au3>

Global $aInFiles[50], $sOutFile, $n = 1, $l = 0
Global $sPath = "C:\Folder" ;Enter path here, to avoid using FileSelectFolder(). (No trailing "\")
Global $aFiles = _FileListToArray($sPath,"*.tif",1)
If @error Then Exit
Global $oPhotoShop = ObjCreate("Photoshop.Application")
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

While $n < $aFiles[0]
    For $i = 0 To 49
        $aInFiles[$i] = $sPath & "\" & $aFiles[$n]
        If $n = $aFiles[0] Then
            ReDim $aInFiles[$i+1]
            ExitLoop
        EndIf
        $n += 1
    Next
    $l += 1
    $sOutFile = $sPath & "\OutFile" & $l & ".pdf"
    ; the next line was just to show the process and can be commented out.
    ; _ArrayDisplay($aInFiles,"Creating " & $sOutFile & " from the following files:")
    $oPhotoShop.MakePDFPresentation($aInFiles, $sOutFile)
WEnd
$oPhotoShop.Quit

Func MyErrFunc()
   ConsoleWrite("COM Error: " & Hex($oMyError.number,8) & @CRLF & "Description: " & $oMyError.description)
Endfunc

Share this post


Link to post
Share on other sites

Hi

I have edited the path, now The FileSelectFolder and _ArrayDisplay will not show up anymore. Thanks again for your help!

However the save PDF filesize is quite huge.

To reduce the PDF file size, in the Menu,

File > Automate > PDF Presentation > Browse

Save Adobe PDF Dialog box

Adobe PDF Preset: (this is a dropdown list)

[High Quality Print] (this is default setting)

[PDF/X-1a:2001]

[PDF/X-3:2002]

[Press Quality]

[smallest File Size]

How do I set Smallest File Size as default setting?

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well I still can't test this as it's not supported in CS5 so here is a stab in the dark. (I'm pretty surprised the other solution worked without much problems actually)

#include <array.au3>
#include <file.au3>

Global $aInFiles[50], $sOutFile, $n = 1, $l = 0
Global $sPath = "C:\Folder" ;Enter path here, to avoid using FileSelectFolder(). (No trailing "\")
Global $aFiles = _FileListToArray($sPath,"*.tif",1)
If @error Then Exit
Global $oPhotoShop = ObjCreate("Photoshop.Application")
Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

#region Set PDF Options
Global $oPSOptions = ObjEvent("Photoshop.PresentationOptions")

;try to apply the "Smallest File Size" profile
$oPSOptions.PDFFileOptions.PresetFile = "Smallest File Size" ;I'm not sure if this is the sting to use.
;~ $oPSOptions.PDFFileOptions.PresetFile("Smallest File Size") ;You could try this too
;;;;;;OR;;;;;;;

;You could also set all relevant settings this way: (uncomment next two lines)

;~ $oPSOptions.PDFFileOptions.Encoding = 2 ;Set encoding to JPG
;~ $oPSOptions.PDFFileOptions.jpegQuality = 1 ;Set JPG quality to a low number (range is 0 to 12)

;Other settings can be found at http://cssdk.host.adobe.com/sdk/1.0/docs/WebHelp/references/csawlib/com/adobe/photoshop/PDFSaveOptions.html
#endregion

While $n < $aFiles[0]
    For $i = 0 To 49
        $aInFiles[$i] = $sPath & "\" & $aFiles[$n]
        If $n = $aFiles[0] Then
            ReDim $aInFiles[$i+1]
            ExitLoop
        EndIf
        $n += 1
    Next
    $l += 1
    $sOutFile = $sPath & "\OutFile" & $l & ".pdf"
    ; the next line was just to show the process and can be commented out.
    ; _ArrayDisplay($aInFiles,"Creating " & $sOutFile & " from the following files:")
    $oPhotoShop.MakePDFPresentation($aInFiles, $sOutFile, $oPSOptions)
WEnd
$oPhotoShop.Quit

Func MyErrFunc()
   ConsoleWrite("COM Error: " & Hex($oMyError.number,8) & @CRLF & "Description: " & $oMyError.description)
Endfunc

The above script demonstrates some ways of changing the PDF export settings. The documentation only specifies that the PresetFile property expects a string, not what that string should be. (could be the full path to the file, or the name with which it shows up in photoshop, or something else.)

As I won't be able to respond to any questions today I hope one of the people reading this has an older CS version and will be able to assist. Either way, just have a look at the link in the script and play around with different settings if you run into any trouble.

Edit: Added the options as an argument for MakePDFPresentation as sahsanu suggested.

Edited by Tvern

Share this post


Link to post
Share on other sites

I don't have knowdledge about this stuff ;-) but I think (maybe I'm wrong) that after the script modification (adding options), the "MakePDFPresentation" should look like this:

$oPhotoShop.MakePDFPresentation($aInFiles, $sOutFile, $oPSOptions)

Share this post


Link to post
Share on other sites

#10 ·  Posted

I don't have knowdledge about this stuff ;-) but I think (maybe I'm wrong) that after the script modification (adding options), the "MakePDFPresentation" should look like this:

$oPhotoShop.MakePDFPresentation($aInFiles, $sOutFile, $oPSOptions)

You're right. I'll edit the exemple, but I'm still not sure if I did it right to start with.

Share this post


Link to post
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
Sign in to follow this  
Followers 0