What are the real possibilities of loading an action.atn file in the Action palette with UXP?

The title says it all, here an unsuccessful attempt.

async function importarAcao() {
      try {
        const fs = require('uxp').storage.localFileSystem;
        const result = await fs.getFileForOpening({ types: ["atn"] });
        const actionSet = await app.actions.load(result);
        app.actionLists.add(actionSet);
      } catch (err) { console.log(err)}
}
await importarAcao()

Any help, whatever it may be, will be greatly appreciated. Thanks!

Error clearly states, that app.actions is undefined. Docs say it should be app.actionTree, if that’s what you’re looking for.

May I ask where did you find this example with actions.load()?

1 Like

Tried this based on extendScript, like try

function loadActions () {
	var actionFile =new File("~/desktop/file.atn");
    if(actionFile.exists){app.load(actionFile)}
};

loadActions ();

Do not compare ExtendScript with UXP. It’s a completely different thing and probably nothing would work. I personally never developed anything on ExtendScript

This works on both uxp and extendScript

app.activeDocument.activeLayers[0]
app.foregroundColor.rgb.hexValue

I don’t want to get here and why someone write code for me, I try to create my solution, if it doesn’t work, that’s why I turn to this community. Your solution above did not work at all someone who has a lot more knowledge will point me in the right direction. I’m hoping that someone here will point me to a solution that I haven’t seen a solution so far

Well… apparently something matches :slight_smile: Wonder if that was intentional by the devs or just coincidence. In any case, if I understand correctly what you’re trying to do, I don’t think UXP supports that. Did you try checking with Alchemist if there’s some output when you load an action?

For the loading action, I believe it would same action as when you open file. But instead of “jpg” you would load “atn”. Maybe you could try open function in DOM but it might fail because it is designed only to open images and return instance of Document.

I will add note to take care of non-image files in app.open

3 Likes

Hi @Jarda thanks for pointing me in the right direction!
Whether app.open DOM was designed just to open images I don’t know, I just know that it actually loaded the set of actions perfectly and I believe it can also load files: csh, tpl, abr, pat asl etc…

async function importarAcao() {
      const fs = require('uxp').storage.localFileSystem;
      const result = await fs.getFileForOpening({ types: ["atn"] });
      app.open(result);
}
await importarAcao()
2 Likes

@Jarda what is the method that checks if an .atn file has already been loaded in the actions palette, I tried to obtain the property in Alchemist, but I only got the number of loaded atn and not the names.

I would use validateReference and then you pass in reference object with ActionSet name in it. If true is returned then it is loaded. That is most performant way. Slower but easier way is to use DOM and loop all action sets and search for name match:

You could simply run the action and if it returns an error, load it, and then run it again. If it doesn’t error out, then it’s loaded. Not terribly elegant, I suppose, but I doubt users could tell the difference.

2 Likes

I didn’t try but I don’t think it does work this way.

@Jarda What have you not tested? What are you referring to?
validate Reference seems like an interesting approach.
For some reason, even with atn loaded, I always get false as a return;

console.log(require("photoshop").action.validateReference({_ref: "ActionSet", _name: "myActionsSet"}))

@AnthonyK , your suggestion will be very helpful if “validate Reference” definitely doesn’t work. Thanks to both of you for the tips

I was referring to hypothetical the error on the second run.

Maybe you could try to add an application reference as a second item in the reference array to test. It will probably won’t help but there are not much other options remaining :smiley:

require("photoshop").action.validateReference({_ref: "ActionSet", _name: "myActionsSet"})

Everything was resolved with correction of an error in writing the reference:
I changed this:

_ref: "ActionSet"

Per:

_ref: "actionSet"

Thank you very much once again!
If anyone needs this, here’s the code working with existing atn verification!

async function importAtnFiles() {
      const fs = require('uxp').storage.localFileSystem;
      const action = require("photoshop").action;
      const atnFile = await fs.getFileForOpening({ types: ["atn"] });
      const ActionSetName = action.validateReference({_ref: "actionSet", _name: atnFile.name.match(/(.*)\.[^\.]+$/)[1]})
      if(ActionSetName == true){app.showAlert(`"${atnFile.name}" has already been loaded!`)}
      else{app.open(atnFile);}
}
importAtnFiles()
4 Likes

In my searches I found topics, but without solution.

@MalbertCunha thanks for sharing, I was looking for this.

2 Likes