Opening Photoshop with argument for running function in UXP plugin

Hello,

I have external python Qt application which is opening photoshop and then running script.
Is there anyway for me to open Photoshop and then run function from uxp plugin?

Python script:

def open_photoshop_and_run_script():
    script_path = os.path.join(tools_path, "/Photoshop/2024/Script/Presets/Scripts/Custom_script.jsx")
    print(script_path)

    try:
        photoshop_path = ""

        if os.name == 'posix':  # macOS
            photoshop_path = "/Applications/Adobe Photoshop 2024/Adobe Photoshop 2024.app"
        elif os.name == 'nt':  # Windows
            photoshop_path = r'C:\Program Files\Adobe\Adobe Photoshop 2024\Photoshop.exe'

        # Close Photoshop if it's already running
        close_photoshop()

        # Wait for a moment to ensure Photoshop is fully closed
        time.sleep(2)

        # Open Photoshop and run the specified script
        if os.name == 'posix':  # macOS
            os.system(f'open -a "{photoshop_path}" --args --jsx "{script_path}"')
        elif os.name == 'nt':  # Windows
            os.system(f'start "" "{photoshop_path}" --jsx "{script_path}"')

    except FileNotFoundError:
        print("Error: Photoshop application not found.")
    except PermissionError:
        print("Error: Permission issue while trying to open Photoshop.")
    except Exception as e:
        print(f"Error: {e}")

If it’s always same function with same params, you could use loadEvent param in manifest and run the function on plugin load

"loadEvent": "startup"

If you want it to depend on some arguments, as you say in the topic title, then IDK :man_shrugging:

I would definitely be interested in this as well. The only way I found so far was to use Apple Script to open Photoshop with directives to literally go to a particular menu and select/click on a particular menu item, to start the corresponding plugin, very clunky (and not very robust). The plugin would then read whatever arguments it needed from a pre-defined .json config, which the calling application would save in a pre-defined location before executing the Apple script file, again not very elegant. One big issue is getting status from Photoshop.

I guess another thing to try could be, what @Karmalakas mentioned, but instead of just running a function you establish a network connection to your Qt app (acting as local server and listening for requests) and communicate asynchronously. The advantage of that would be that you could pass arguments as well as status back and forth, although obviously that’s much more involved.

In any case, calling Photoshop, specifying a plugin and arguments through command line and getting a status return seems like it would be every VFX pipeline engineer’s dream… at least it’s mine :smiley: