Photoshop, Python and the script listener

hello folks, Long time no see!

I have been tasked with porting our javascripts to python. I have traversed the first bit which was triggering a python script via JSX thx to some help from Adam Pletcher’s old blogpost, and some tips from Matt Greene.

Now I am faced with the problem of porting some legacy script-listener portions of our javascripts to python, and I can’t get them to execute. I found this blogpost by Pete Hanshaw explaining exactly what i want to do, but the examples do not work for me. I have not found a way to get any useful warnings or errors via COM, so i am pretty much up a creek. Does anyone have any advice?

-R

can you post an example? I basically just do what he does when porting script listener code to python and haven’t had any issues

Javascript launching script (triggers python code):

function pythonExec(pyScriptPath)
{
var bat = new File(Folder.temp + “/TempPhotoshopScript.bat”)
bat.open(“w”)
bat.writeln ("d:/build/Tools/Python/2.7-x64/pythonw.exe “” + pyScriptPath + “” ")
bat.writeln(“start /b “” cmd /c del “%~f0”&exit /b”)
//bat.writeln(“pause”)

bat.close()
bat.execute()

}
pythonExec(“d:/build/Tools/PyScript/photoshop/Test2.py”)

python code:

import comtypes.client
import sys
import Paths

def testOpen():
objApp = comtypes.client.CreateObject(‘Photoshop.Application’)

#set dialog mode to none
dialogMode = 3

idOpn = objApp.CharIDToTypeID( "Opn " )
desc1 = CreateObject( "Photoshop.ActionDescriptor" )
idnull = objApp.CharIDToTypeID( "null" )
desc1.PutPath( idnull, "D:/temp/blah.psd" )
objApp.ExecuteAction( idOpn, desc1, dialogMode )

testOpen()

Problem solved:

Once I got debugging info outta wing i found my problem, my copmtypes reference for create object was wrong (twice Ack!). Originally I had:
desc1 = CreateObject( “Photoshop.ActionDescriptor” )

then I mistakenly tried:
desc1 = objApp.CreateObject( “Photoshop.ActionDescriptor” )

but finally I noticed that the proper reference for CreateObject to comtypes should be:
desc1 = comtypes.client.CreateObject( “Photoshop.ActionDescriptor” )

yay!