How to load PS Actions through UXP

I want to load the actions on the path that I have specified in the script, but we cannot access the path directly through script via uxp (right?) and move the files there. Is there another way to take the actions from a path where the project is standing and load them into ps via script?

1 Like

If you want the UXP script, you cannot get the path automatically as you say. It will be roughly the same code on this page.

If it is a UXP plugin, you can specify the path as you like, so it can load an atn file in the same folder as the document you have open, for example.

const { localFileSystem } = require('uxp').storage ;
const { action, app, core } = require('photoshop') ;

const main = async () => {
  try {
    await core.executeAsModal(
      async (control) => {
        const doc = app.activeDocument ;
        if(doc == null) {
          app.showAlert(`Please execute with the document open.`) ;
          return ;

        const docPath = doc.path ;
        if(docPath === '') {
          app.showAlert(`Please save the document and then execute it.`) ;
          return ;

        // get atn file in same folder as active document
        const parentPath = path.dirname(docPath) ;
        const atnName = 'set1.atn' ;
        const atnPath = path.join(parentPath, atnName) ;
        const atnEntry = await localFileSystem.getEntryWithUrl(atnPath) ;

        // load an action set with the same name if it does not exist
        const actionSetName = path.basename(atnPath, '.atn') ;
        const whetherExistsActionSet = action.validateReference({_ref: 'actionSet', _name: actionSetName}) ;
        if(whetherExistsActionSet) {
          await app.showAlert(`No action set was loaded since it already exists.`) ;
          return ;
        } else {
          await ;
          await app.showAlert(`ActionSet '${actionSetName}' has been loaded.`) ;

      {'commandName': 'Load Action Set'}
    ) ;
  } catch(e) {
    await app.showAlert(e) ;
} ;
1 Like

first of all thank you for your answer. However, in order to load the action by this code, my ps file must be registered, but what I want to do is to load the action from the path of the main script that I prepared for UXP.
I understood your approach here, since we did not have direct access to the path, you tried to find the path from the doc, it makes sense, but what I need is to find the path where the script is located in this way.

Can you use ExtendScript instead? It is easier to achieve.

  * @file load action set from atn file in same folder as active jsx script
  * @version 1.0.0
  * @author
  * @copyright © 2023

(function() {
  // get atn file in same folder as active jsx script
  var scriptFile = new File($.fileName) ;
  var parentPath = decodeURIComponent(scriptFile.parent.fullName) ;
  var actionSetName = 'set1' ;
  var atnName = actionSetName + '.atn' ;
  var atnPath = parentPath + '/' + atnName ;
  var atnEntry = new File(atnPath) ;
  if(atnEntry.exists) {
    app.load(atnEntry) ;
    alert("ActionSet '" + actionSetName + "' has been loaded.") ;
})() ;

Haha actually what I was trying to do was move my project from extendScript to UXP. Thank you very much for your help, but I think we will follow the developments of UXP in this regard. (Thanks again for your support)

1 Like