Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do you creating a sub menu of actions to pick from using script

Explorer ,
Aug 30, 2022 Aug 30, 2022

I wish to have a button in my photoshop actions which when pressed open up a window with buttons to choce further actions from.  I use a lot of actions and this would help me find the right set more easly 

TOPICS
Actions and scripting
868
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Sep 14, 2022 Sep 14, 2022

try this:

 

var s2t = stringIDToTypeID,
    atn = getActionsList(),
    cur = getActionName();

if (cur && atn[cur]) {
    var cursor = (getXY()),
        w = new Window("dialog", cur);
    w.preferredSize = [200, 200];
    w.spacing = 0;
    w.location = [cursor[0], cursor[1] + 100]
    for (var i = 0; i < atn[cur].length; i++) {
        var b = w.add('button')
        b.text = atn[cur][i];
        b.onClick = function () {
            w.close()
            doAction(this.text, cur)
        }
  
...
Translate
Adobe
Community Expert ,
Aug 30, 2022 Aug 30, 2022

Do you have any Photoshop Scripting or general JavaScript experience? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 31, 2022 Aug 31, 2022

I know enough to edit java but not to created it from scratch  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2022 Aug 30, 2022

The following extension can find actions by a search filter:

 

https://exchange.adobe.com/creativecloud.details.101656.action-launcher-free.html

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2022 Aug 30, 2022

Are you aware of button mode in Photoshop? Buttons can be colorized for easier navigation or find.

colorize action for button mode.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 31, 2022 Aug 31, 2022

Perhaps you will be satisfied with this option: When launched, the script gets the name of the action from which it was launched, then searches for a set with the same name among the loaded ones and displays a window with buttons, each of which launches the action of the specified set. Not perfect, but it works.

 

var s2t = stringIDToTypeID,
    atn = getActionsList(),
    cur = null;

try {
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('name'));
    r.putEnumerated(s2t('action'), s2t('ordinal'), s2t('targetEnum'));
    cur = executeActionGet(r).getString(p);
} catch (e) { }

if (cur && atn[cur]) {
    var cursor = (getXY()),
        w = new Window("dialog", cur);
    w.preferredSize = [200, 200];
    w.spacing = 0;
    w.location = [cursor[0], cursor[1]+100]
    for (var i = 0; i < atn[cur].length; i++) {
        var b = w.add('button')
        b.text = atn[cur][i];
        b.onClick = function () {
            w.close()
            doAction(this.text, cur)
        }
    }
    w.show();

    function getXY() {
        var w = new Window("dialog {alignChildren: ['fill','fill'], margins: 0}"),
            g = w.add("button"),
            X, Y;
        w.preferredSize = [$.screens[0].right, $.screens[0].bottom]
        g.addEventListener('mouseover', handler)
        function handler(evt) { w.close(); X = evt.screenX, Y = evt.screenY }
        w.show();
        return [X, Y]
    }
}

function getActionsList() {
    var output = {},
        setCounter = 1
    while (true) {
        (r = new ActionReference()).putIndex(s2t('actionSet'), setCounter);
        try { desc = executeActionGet(r) } catch (e) { break; }
        var numberChildren = desc.hasKey(s2t('numberOfChildren')) ? desc.getInteger(s2t('numberOfChildren')) : 0
        if (numberChildren > 0) {
            output[desc.getString(s2t('name'))] = getActionList(setCounter, numberChildren)
        }
        setCounter++
    }
    return output;

    function getActionList(setIndex, numChildren) {
        var current = []
        for (var i = 1; i <= numChildren; i++) {
            (r = new ActionReference()).putIndex(s2t('action'), i);
            r.putIndex(s2t('actionSet'), setIndex)
            current.push(executeActionGet(r).getString(s2t('name')))
        }
        return current
    }
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 31, 2022 Aug 31, 2022

This looks really useful, thank you. I will try it out tomorrow.

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 14, 2022 Sep 14, 2022

Hi jazz-y

I Finally got around to trying out this Script. It works as it should when i create it but then not when i play the action after. The pathway is there to the action's laoction and I have checked the script again. any ideas? I am really keen to get this working.

 

Thank you again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 14, 2022 Sep 14, 2022

try this:

 

var s2t = stringIDToTypeID,
    atn = getActionsList(),
    cur = getActionName();

if (cur && atn[cur]) {
    var cursor = (getXY()),
        w = new Window("dialog", cur);
    w.preferredSize = [200, 200];
    w.spacing = 0;
    w.location = [cursor[0], cursor[1] + 100]
    for (var i = 0; i < atn[cur].length; i++) {
        var b = w.add('button')
        b.text = atn[cur][i];
        b.onClick = function () {
            w.close()
            doAction(this.text, cur)
        }
    }
    w.show();

    function getXY() {
        var w = new Window("dialog {alignChildren: ['fill','fill'], margins: 0}"),
            g = w.add("button"),
            X, Y;
        w.preferredSize = [$.screens[0].right, $.screens[0].bottom]
        g.addEventListener('mouseover', handler)
        function handler(evt) { w.close(); X = evt.screenX, Y = evt.screenY }
        w.show();
        return [X, Y]
    }
}

function getActionsList() {
    var output = {},
        setCounter = 1
    while (true) {
        (r = new ActionReference()).putIndex(s2t('actionSet'), setCounter);
        try { desc = executeActionGet(r) } catch (e) { break; }
        var numberChildren = desc.hasKey(s2t('numberOfChildren')) ? desc.getInteger(s2t('numberOfChildren')) : 0
        if (numberChildren > 0) {
            output[desc.getString(s2t('name'))] = getActionList(setCounter, numberChildren)
        }
        setCounter++
    }
    return output;

    function getActionList(setIndex, numChildren) {
        var current = []
        for (var i = 1; i <= numChildren; i++) {
            (r = new ActionReference()).putIndex(s2t('action'), i);
            r.putIndex(s2t('actionSet'), setIndex)
            current.push(executeActionGet(r).getString(s2t('name')))
        }
        return current
    }
}

function getActionName() {
    var atn;
    try {
        (r = new ActionReference()).putEnumerated(s2t('action'), s2t('ordinal'), s2t('targetEnum'));
        var parent = executeActionGet(r).getString(s2t('parentName')),
            title = executeActionGet(r).getString(s2t('name'));
        try {
            (r = new ActionReference()).putName(s2t('actionSet'), title);
            executeActionGet(r).getInteger(s2t('itemIndex'));
            atn = title;
        } catch (e) {
            (r = new ActionReference()).putName(s2t('actionSet'), parent);
            executeActionGet(r).getInteger(s2t('itemIndex'));
            atn = parent;
        }
    }
    catch (e) { atn = null }
    return atn;
}

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 16, 2022 Sep 16, 2022

Thank you, that works everytime, you have been a great help. 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 22, 2022 Sep 22, 2022

Hi sorry there is one last glich, when i run the action and the submenu of action come up, what ever one i press it plays the bottom one in that set. Thank you again for your help.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 22, 2022 Sep 22, 2022

change line

 

doAction(b.text, cur)

to:

 

doAction(this.text, cur)

 This should fix the issue.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 22, 2022 Sep 22, 2022
LATEST

Just made the change, all works as it should. Thank you for your help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2022 Aug 31, 2022
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 01, 2022 Sep 01, 2022

Thank you this looks great, I have over 150 diffrent actions and this will save alot of time. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines