Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[request] Way to export as webp in a script added in actions #59

Open
lucianahanan opened this issue Dec 24, 2023 · 9 comments
Open

[request] Way to export as webp in a script added in actions #59

lucianahanan opened this issue Dec 24, 2023 · 9 comments

Comments

@lucianahanan
Copy link

Hi.

I'm trying to make a script that saves the current file as webp, that will get added in actions. I want to you your webp exporter. But I can't find a way to make the javascript ( ExtendedScript ) reference your extension instead of the regular webp.

Can you make a way of making it, with an example script, if possible!?

Thanks!

@y-guyon
Copy link
Collaborator

y-guyon commented Dec 26, 2023

Thank you for the report.
May I know why Adobe's built-in regular WebP script action does not fulfill your needs?

I believe Photoshop overrides plug-ins for a given file format, so WebPShop may have to mock another file format (not WebP) for this action to work. I doubt this is worth the effort and user-side confusion since Photoshop has partial built-in WebP support.

@lucianahanan
Copy link
Author

I like your webp better :)

@y-guyon
Copy link
Collaborator

y-guyon commented Jan 2, 2024

I like your webp better :)

Could you provide more explicit details?

@lucianahanan
Copy link
Author

I was making an action to export files as webp, the idea was using your webp as extension. But chatgpt said that your extension did not provide any way to pass the current file path to the save as. I tried to make a js function ( pre ES in old style for photoshop ), but still it did not work with your webp.

Without that, I would have to keep editing the action everything the folder changes.

@y-guyon
Copy link
Collaborator

y-guyon commented Jan 3, 2024

I was making an action to export files as webp, the idea was using your webp as extension.

I vaguely remember that the "Save" action was working in Photoshop versions prior to 23.2. Is the "Export" action different?
What is your Photoshop version?

chatgpt said that your extension did not provide any way to pass the current file path to the save as

This part should be handled by Photoshop, not by the WebPShop plug-in.
FormatRecordPtr is an argument of PluginMain() and is used to write bytes to a file. WebPShop has no knowledge of any file path.

Without that, I would have to keep editing the action everything the folder changes.

If automation is an important part of your process, I suggest looking at other solutions than Photoshop scripts, in case it fulfills your needs better. For example you could call the cwebp binary in the command line or from a bash/batch script instead of using Photoshop.
I can understand that keeping the whole workflow in Photoshop is easier though.

@lucianahanan
Copy link
Author

Look. this is the script I tried to execute, as a workaround to the fact that the webshop does not let me pass the current file path to it in the visual actions panel. but I could not make it work. maybe you have an idea over there. I'm using photoshop 2023

function actionCommands() {
    var psAction = require("photoshop").action;
    var app = require("photoshop").app;

    // Get the current document
    var currentDoc = app.activeDocument;

    // Retrieve the file path of the current document
    var filePath = currentDoc.filePath;

    // Save command with dynamic file path
    var command = {
        "_obj": "save",
        "as": {
            "$wrtc": 2,
            "$wrte": false,
            "$wrtl": true,
            "$wrtp": false,
            "$wrtq": 75,
            "$wrtx": false,
            "_obj": "Google WebPShop"
        },
        "documentID": currentDoc._id,
        "in": {
            "_kind": "local",
            "_path": filePath
        },
        "lowerCase": true
    };

    // Execute the command
    psAction.batchPlay([command], {});
}

actionCommands();

@y-guyon
Copy link
Collaborator

y-guyon commented Jan 3, 2024

Thank you for sharing. Unfortunately I do not have access to any Photoshop environment at the moment and I seemingly know less about Photoshop scripting than you do.

I can imagine it is possible to get the value of the _path resource within the WebPShop plug-in and to write the file directly. However, as I said above, going through the Photoshop SDK API is probably the safest, most platform-independent option.
I believe your issue or question is related to Photoshop itself and out of the scope of the WebPShop plug-in. Does it work with another format plug-in?

// Retrieve the file path of the current document
var filePath = currentDoc.filePath;
...
  "_path": filePath

Could it fail because it tries to overwrite the document that is currently opened? What about using filePath + ".webp" instead?

@lucianahanan
Copy link
Author

lucianahanan commented Jan 3, 2024 via email

@y-guyon
Copy link
Collaborator

y-guyon commented Jan 3, 2024

I got the PS to test, and can help you testing if you like.

That is kind of you but I will not have enough time to work on this that way.

Yes it work with any other extension.

Do you have an example of a plug-in that works the way you described it? Maybe it is open source and similar enough to WebPShop to import the necessary parts.

webpshop does not understand the current file path

But the current file path currentDoc.filePath is unlikely to be a .webp file, right?
Or was it just an example, and you meant "webpshop does not understand custom file paths given through in > _path"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants