Photoshop UXP - Timeline and Frames Access

I have the following Code that works fine in an old style .jsx file:

function getFrameCount() {
    var r = new ActionReference();
    r.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('frameCount'));
    r.putClass(stringIDToTypeID('animationClass'));
    var ret = executeActionGet(r);
    return ret.getInteger(stringIDToTypeID('frameCount'));
}

I’ve been attempting all day to either do this natively within UXP or to figure out how to call a working .jsx script from a button in my UXP plugin.

I can’t find a way to get timeline queries working in UXP and would love some guidance

Record an action running your script. Then record another acion running the first action. Then assign second action to your button in UXP

NB: This may stop working (if it still does) at any point if Adobe decides to patch this loophole

That process is able to translate into batchPlay.

const { app, action } = require('photoshop') ;

const main = async () => {
  try {
    const info = await action.batchPlay(
      [
        {
          _obj: 'get',
          _target: [
            {_property: 'frameCount'},
            {
              _ref: 'animationClass',
              _enum: 'ordinal',
              _value: 'targetEnum'
            }
          ],
          _options: {
            dialogOptions: 'dontDisplay'
          }
        }
      ], 
  
      {}
    ) ;

    const count = info[0].frameCount ;
    app.showAlert(count) ;
  } catch(e) {
    app.showAlert(e) ;
  }
} ;