Copy link to clipboard
Copied
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 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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Here is what is going on https://www.screencast.com/t/SNH6aQeVy
Running CS6 on Windows.
Exactly same thing happens in Ps 2021.
Copy link to clipboard
Copied
Curious... What happens if you remove the two debugger lines:
$.writeln(currPath);
$.writeln(incr);
Thanks for the feedback.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
He rather asked if it is going to launch ExtendScript ToolKit.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
// 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}
};
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
I see no immediate option for that.
I think using Scripting to edit existing Actions in Photoshop is a problematic approach.
Copy link to clipboard
Copied
sTT = stringIDToTypeID;
(ref = new ActionReference()).putEnumerated
(sTT('path'), sTT('ordinal'), sTT('targetEnum'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref),
executeAction(sTT('duplicate'), dsc)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
@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?
Copy link to clipboard
Copied
No worries, that was not to you, but Bojan Živković 😉
The workaround may be probably code posted 22m ago
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
He posted 2 scripts. You are interested only in the first one (you may record to action).
Copy link to clipboard
Copied
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))
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
It's not same but very similar, so you shouldn't have any problem. To decreaase use --i.
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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--};
Copy link to clipboard
Copied
@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).
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@Bojan Živković wrote:
@Stephen Marsh send code to someone else to test on Windows machine, for
example.
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.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more