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

Script to select next path in the Paths panel and use Insert Path menu item from Actions panel

Community Expert ,
Feb 10, 2022 Feb 10, 2022

I need script for very boring task if possible to automate at least something in this work which consist of several thousand repeats multiplied by 5 steps. In essence I am replacing Set Work Path step with new path. Here are steps I am taking to accomplish task:

 

  • Select Set Work Path step in action
  • Select next path in Paths panel
  • Use Insert Path from Actions panel menu
  • Select previous action step Set Work Path
  • Delete Set Work Path
  • Select next Set Work Path step in action
  • Repeat....

select next path and insert path item.jpg

TOPICS
Actions and scripting , Windows
3.2K
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

Community Expert , Feb 10, 2022 Feb 10, 2022
// select next path;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thisPathIndex = selectedPath ();
if (thisPathIndex != null) {
    if (thisPathIndex == activeDocument.pathItems.length) {thisPathIndex = 1}
    else {thisPathIndex++};
    var desc28 = new ActionDescriptor();
        var ref5 = new ActionReference();
        ref5.putIndex( stringIDToTypeID( "path" ), thisPathIndex );
    desc28.putReference( stringIDToTypeID( "null" ), ref5 );
executeAction( stringIDToType
...
Translate
Adobe
Community Expert ,
Feb 10, 2022 Feb 10, 2022

Thanks @Stephen Marsh , this script is selecting path below currently selected in the Paths panel but only briefly and then returns to originally selected and opens some dialogue.

selectnextpath script.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
Community Expert ,
Feb 10, 2022 Feb 10, 2022

Don't run the script through ESTK, just run the script in Photoshop directly, do you get different behaviour?

 

I tested in Ps version 2021 on Mac, using VS Code debugger and direct in Photoshop and it works as expected.

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 ,
Feb 10, 2022 Feb 10, 2022

Here is what is going on https://www.screencast.com/t/SNH6aQeVy

Running CS6 on Windows.

Exactly same thing happens in Ps 2021.

 

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 ,
Feb 11, 2022 Feb 11, 2022

Curious... What happens if you remove the two debugger lines:

 

$.writeln(currPath);

$.writeln(incr);

 

Thanks for the feedback. 

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 ,
Feb 11, 2022 Feb 11, 2022

Same thing, I commented lines and everything works in the same manner: script will quickly select below path and immediately jump back to originaly selected (above) path.

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 ,
Feb 11, 2022 Feb 11, 2022

Oh well, this is what becomes of being a hack!

 

I'm glad that @c.pfaffenbichler posted a workable alternative... I can't even hack that one to decrement to select previous layer (I know that you want next, but previous should be just as useful in other situations).

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

He rather asked if it is going to launch ExtendScript ToolKit.

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

Script ran from Ps shouldn't open ESTK. Beofre you execute .jsx, insert at beginning:

 

#target photoshop

 

Quit ToolKit and Photoshop and see which release of Photoshop is going to be opened.

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 ,
Feb 10, 2022 Feb 10, 2022
// select next path;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thisPathIndex = selectedPath ();
if (thisPathIndex != null) {
    if (thisPathIndex == activeDocument.pathItems.length) {thisPathIndex = 1}
    else {thisPathIndex++};
    var desc28 = new ActionDescriptor();
        var ref5 = new ActionReference();
        ref5.putIndex( stringIDToTypeID( "path" ), thisPathIndex );
    desc28.putReference( stringIDToTypeID( "null" ), ref5 );
executeAction( stringIDToTypeID( "select" ), desc28, DialogModes.NO );
};
};
////// determine selected path index //////
function selectedPath () {
    try {
    var ref = new ActionReference(); 
    ref.putEnumerated( charIDToTypeID("Path"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
    var desc = executeActionGet(ref);
    var theIndex = desc.getInteger(stringIDToTypeID("itemIndex"));
    return theIndex
    } catch (e) {return null}
    };
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 ,
Feb 10, 2022 Feb 10, 2022

This works, it is selecting next path in the Paths panel. Is it possible to add another step in process: use Insert Path menu item from Actions panel menu?

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 ,
Feb 10, 2022 Feb 10, 2022

I see no immediate option for that. 

I think using Scripting to edit existing Actions in Photoshop is a problematic approach. 

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022
sTT = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated
(sTT('path'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref),
executeAction(sTT('duplicate'), dsc)
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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

This code is not an answer for original question. It does just the easiest part of job, I offered as well to share with other steps. Additionally Stephen_A_Marsh posted 'the same' code earlier.

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 ,
Feb 11, 2022 Feb 11, 2022

@Kukurykus wrote:

This code is not an answer for original question. It does just the easiest part of job, I offered as well to share with other steps. Additionally Stephen_A_Marsh posted 'the same' code earlier.


I did not mark my post the »Correct Answer« so feel free to change that ranking if possible. 

 

Anyway, I see no immediate option to »Insert Path« into the Action via Script – do you have a solution for that? 

Though I wonder what the point of this step is anyway; is the Action with those newly included Paths intended to be run on another file later on? 

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

No worries, that was not to you, but Bojan Živković ðŸ˜‰

 

The workaround may be probably code posted 22m ago

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 ,
Feb 12, 2022 Feb 12, 2022

@c.pfaffenbichler 

 

I like how your version of the next/prev path selection script cycles back to the top when it hits the bottom. My script just stops at the bottom.

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

He posted 2 scripts. You are interested only in the first one (you may record to action).

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

 

l = activeDocument.channels.length
sTT = stringIDToTypeID; (ref = new ActionReference())
.putEnumerated(sTT('channel'), sTT('ordinal'), sTT('targetEnum'));
(i = executeActionGet(ref).getInteger(sTT('itemIndex'))) > 0 && i < l
&& ((ref = new ActionReference()).putIndex(sTT('channel'), ++i),
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref),
executeAction(sTT('select'), dsc))

 

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 ,
Feb 11, 2022 Feb 11, 2022

@Kukurykus - Thank you for the select next channel code, I have the same issue in that I'd like to edit it to decrement to select the previous channel, however I can't make it work. 

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

It's not same but very similar, so you shouldn't have any problem. To decreaase use --i.

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 ,
Feb 11, 2022 Feb 11, 2022

@Kukurykus wrote:

It's not same but very similar, so you shouldn't have any problem. To decreaase use --i.


 

If I wasn't having problems hacking the code I wouldn't have posted that I was having problems.

 

I have tried both single and double decrement operators as both prefix and postfix. I had the same issue trying to make a previous path version of the script posted by @c.pfaffenbichler â€“ it is not that easy. In both cases I can't make a version that selects the previous path or channel.

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
LEGEND ,
Feb 11, 2022 Feb 11, 2022

So you don't talk of yours and mine script, but his. Then change 2 lines to:

 

if (thisPathIndex==1){thisPathIndex=activeDocument.pathItems.length}
else{thisPathIndex--};

 

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 ,
Feb 11, 2022 Feb 11, 2022

@Kukurykus wrote:

So you don't talk of yours and mine script, but his. Then change 2 lines to:

 

if (thisPathIndex==1){thisPathIndex=activeDocument.pathItems.length}
else{thisPathIndex--};

 


 

Sorry if I was not clear... I can't make a previous version of your channel script either. It is "not that easy" (for me).

 

Thank you, I now have a working version of the script from @c.pfaffenbichler to select the previous path!

 

EDIT: No, I am not talking about my path scripts, I made both previous and next versions, however due to the issues reported by @Bojan Živković with my code, I would prefer versions that reportedly run without issues (even if I can't reproduce the same issue, it has made me doubt my code).

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 ,
Feb 12, 2022 Feb 12, 2022
@Stephen Marsh send code to someone else to test on Windows machine, for
example.

Bojan Živković
bojan2273@gmail.com
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 ,
Feb 12, 2022 Feb 12, 2022

@Bojan Živković wrote:
@Stephen Marsh send code to someone else to test on Windows machine, for
example.

 

 

@Bojan Živković 

 

Thanks, I can test in Windows, it is just not convenient. So I justed tested my original two scripts in Win 10 and Ps 2022 and they work the same as on the Mac. I used browse, I didn't install the scripts, however I can't see why the behaviour would be different to browse. ESTK does not pop up, the next or previous path selected by the script remains selected.

 

So, I can't reproduce the issues you showed on either Mac or Windows in multiple versions of Photoshop.

 

I have updated the code in my previous posts to use ++ and -- increment/decrement operators rather than adding +1 or subtracting -1 from the curent path index, which is a different way of doing the same thing. I would be interested if that has a different outcome, but apart from that I can't explain your issues. Perhaps you need to reset prefs.

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