Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


photoshop javascript, new Map(), forEach(), example in uxp guide not working

Explorer ,
Sep 14, 2021 Sep 14, 2021

Copy link to clipboard

Copied

This action could be particularly useful to me - if it worked.

 

Actions and ActionSets

 

const app = require('photoshop').app; const allActionSets = app.actionTree; const firstActionSet = allActionSets[0]; let actions = new Map(); // a JS Map allows easy "find by name" operations firstActionSet.actions.forEach((action) => { actions.set(action.name, action)}); const myAction = actions.get("Wood Frame - 50 pixel"); if (myAction) { // user may have deleted this action await myAction.play(); }

 

I omited 'let' in line 4 (invalid in javascript react),

I get an Error 23: > does not have a value. line 5; firstActionSet... 

It's painful trying to learn with a poor API reference.

 

In my test, I have the "Wood Frame - 50 pixel" action loaded in the palette.

 

Anyway, I would prefer a grep search.

 

1. First, What is wrong with the code in the Adobe guide?

     So, I might find / solve errors myself elsewhere in the guide.

 

2. A grep search would be much less tedious code to maintain when searching for actions.sets in allActionSets;

    eg. I have ActionSets named: Portrait retouching ver.2, Print Preflight ver.3 

    So, I want to grep search eg;  /print preflight.*/i

 

"learning a new language humbles a person when they see a 5 year old native speaker can talk"

-------------------------------------------

mac / photoshop cc / latest versions

 

TOPICS
Actions and scripting, macOS

Views

35

Likes

Translate

Translate

Report

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
LEGEND ,
Sep 14, 2021 Sep 14, 2021

Copy link to clipboard

Copied

2. In general the way to implement grep searches is to do a full enumeration of values, and test each one against the regular expression yourself. This is outside the scope of the API, just normal JavaScript.

Likes

Translate

Translate

Report

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, 2021 Sep 14, 2021

Copy link to clipboard

Copied

Right! the first goal is to just load allActionSets without getting an Error 23 > does not have a value.

It's rare I can actually use or learn from the code in the UXP guide because the example code often fails.

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Sep 14, 2021 Sep 14, 2021

Copy link to clipboard

Copied

LATEST

Likes

Translate

Translate

Report

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