Copy link to clipboard
Copied
Hi,
I want to write a LR plugin which opens the selected pictures in PS CC and execute an action in PS, save the image and add it to the catalog. Any idea how to proceed?
Copy link to clipboard
Copied
You don't need to write a plugin to do this. You can define an export preset that exports the photo(s) and then runs an export post-processing action that runs a Photoshop droplet invoking the desired action. The export preset sets these options:
Export To: Same Folder As Original Photo
Add To This Catalog
Add To Stack: Above Original
Include: All Metadata
Write Keywords As Lightroom Hierarchy
Unfortunately, CC 2015.4 and .5 broke the invocation of droplets as post-processing actions, but Adobe has indicated that will be fixed in the next release. Meanwhile, there's a workaround for the bug: Lightroom: wav files will not import | Photoshop Family Customer Community
Copy link to clipboard
Copied
Oops, here's the correct link: Lightroom: Droplets no longer work with export presets (CC 2015.4) | Photoshop Family Customer Commu...
Copy link to clipboard
Copied
Ups, I forget an important piece. The selected images have to be opened as layers in one PSD file. The action will work on the layers. And for end users it should be an "one click action" in LR.
Copy link to clipboard
Copied
The selected images have to be opened as layers in one PSD file.
That will be a fair amount more work, but definitely feasible. The approach:
1. The LR plugin runs an Applescript (Mac) or VBScript (Windows) using LrTasks.execute(), passing the paths of the selected photos as command-line arguments to the script.
2. The Applescript/VBScript invokes PS, loading the images as layers into a single PSD document. You might look at the script "Load Files into Stack.jsx" supplied with PS for an example of how to script that. The script then invokes the action and then saves the PSD.
3. The LR plugin then adds the saved PSD to the catalog using catalog:addPhoto ().
For documentation, start with LR SDK and PS scripting documentation. See my post about getting started with SDK development: Re: Sample code for a publish service?
Copy link to clipboard
Copied
I think the approach is broadly right...
1. JavaScript is probably a better choice as it's cross platform and tends to have more examples to follow. That's what "Load Files into Stack.jsx" is, after all.
2. With a script (which might be generated on the fly) you might not even need an action, and dependence on an action can add unnecessary complication.
3. The Lr plugin would not know when the file is ready for importing. To automate the process, maybe start the plugin operation by generating and importing a tiny TIF file which the script can then modify, or include a call to Lightroom's url handler at the end of the script.
Copy link to clipboard
Copied
JavaScript is probably a better choice as it's cross platform and tends to have more examples to follow.
My understanding is that PS Javascript scripts can't be executed outside of Photoshop (e.g. from the shell/command line) -- they can only be executed from the PS File > Scripts menu. Whereas VBScript and Applescript scripts can be executed from the command line/shell.
I think the core issue is that PS Javascript scripts don't have access to the Photoshop object model when they're executed outside of Photoshop, whereas VBScript and Applescript scripts do (via COM on Windows, Apple Events on Mac).
It would certainly be easier for cross-platform plugins if I were incorrect.
Copy link to clipboard
Copied
johnrellis wrote:
JavaScript is probably a better choice as it's cross platform and tends to have more examples to follow.My understanding is that PS Javascript scripts can't be executed outside of Photoshop (e.g. from the shell/command line) -- they can only be executed from the PS File > Scripts menu. Whereas VBScript and Applescript scripts can be executed from the command line/shell.
I know it goes against what I said earlier about complication, but the trick is for the plugin to trigger an action/droplet whose only task is to run the script.
BridgeTalk is also available, and is what Lr already uses to automate Photoshop activity, but I've never got round to seeing if it's possible to run it from a plugin.
Copy link to clipboard
Copied
The Lr plugin would not know when the file is ready for importing.
My memory from a project many years ago is that the activeDocument.SaveAs() method invoked from a VBScript wouldn't return until the save actually completed. Thus, LrTasks.execute() invoking such a script wouldn't return until the save is complete. Is that incorrect?
Copy link to clipboard
Copied
So it is probably better to generate and import the file earlier in the process.
Copy link to clipboard
Copied
what I would like to have is the "Open in PS as Layer" function which is available in the menu as an API. And then trigger a PS script/action. As I understood this is not possible.
So I can't automate the process and have to follow a manual process -> select images in LR -> Open as Layers in PS -> Switch to PS, execute Script -> Save file in PS -> switch back to LR.
A function "Open in PS as layers and execute script" would be the function I'm looking for.
Copy link to clipboard
Copied
So I can't automate the process
If you're looking for very high-level automation akin to OS X Automator or Photoshop actions, that's accurate. But as we've discussed, you can fully automate the process by writing a plugin and some Photoshop scripts, probably on the order of 100 - 300 lines of code in total.