Question about migrating CEP plugin to UXP

It’s possible, yet a little complicated:

  1. Navigate Photoshop’s menu to match the plugin by name, then the panel by name.
  2. Read out the apps property panelList to check if the panel is currently visible
  3. Programmatically open the panel by its menu command

To save you some time:
(remove types if you’re not using Typescript)

export const showPluginPanel = (pluginName: string, panelName: string, closeIfOpen: boolean = false) => {
  const menuBar = getAppProperty('menuBarInfo')
  const plugins = menuBar.submenu.find(item => item.menuID === 7200)
  const plugin = plugins.submenu.find(item => item.title === pluginName)
  const panel = plugin.submenu.find(item => item.title === panelName)
  const panelState = getAppProperty('panelList').find(p => p.name === panelName)
  if (!panelState.visible || panelState.obscured || closeIfOpen) {
    performMenuCommand(panel.command)
  }
}

export const appRef = { _ref: 'application', _enum: 'ordinal', _value: 'targetEnum' }

export function getAppProperty<T extends keyof ApplicationDescriptor>(prop: T): ApplicationDescriptor[T] {
  return photoshop.action.batchPlay([
    {
      _obj: 'get',
      _target: [{ _property: prop }, appRef],
    },
  ], { synchronousExecution: true })[0][prop]
}

export function performMenuCommand(commandID: number) {
  photoshop.core.performMenuCommand({
    commandID
  });
}
2 Likes