How to bypass the error "The command [name] is currenly unavailable"

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

artibay@gmail.com
Posts: 1
Joined: Mon Feb 24, 2020 3:35 pm

How to bypass the error "The command [name] is currenly unavailable"

Post by artibay@gmail.com »

How to bypass the error "The command [name] is currenly unavailable". When i want to example copy layer

Code: Select all

app.activeDocument.selection.copy()
and when no layer is selected i get this error.
I want to create panel with icons copy and paste layer. How to get if layer or group is not selected?
User avatar
Dormeur74
Posts: 36
Joined: Mon Oct 03, 2016 4:56 am

Re: How to bypass the error "The command [name] is currenly unavailable"

Post by Dormeur74 »

It would be better to give us either the whole script, or the block of lines just before the function copy(). Not possible to help or to find the bug. I think you are copying a part of a layer where there is nothing. If your instruction is in a main function, set a "return;" command just before this line to control if there is a selection and on which layer.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: How to bypass the error "The command [name] is currenly unavailable"

Post by Kukurykus »

That's a bug. You can use following code to make selection of last selected layer if for some reason it lost selection. And remember if you didn't know that, to copy layer, that layer has to be not only selected in Layers panel, but also have selection (usually you make by CTRL A):

Code: Select all

activeDocument.suspendHistory('', ''), sTT = stringIDToTypeID;
(ref = new ActionReference()).putProperty(sTT('historyState'), sTT('currentHistoryState'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), executeAction(sTT('delete'), dsc)
schroef
Posts: 33
Joined: Sat Apr 11, 2020 6:22 am

Re: How to bypass the error "The command [name] is currenly unavailable"

Post by schroef »

@Kukurykus

perhaps post the full script. Your missing sTT part

Which is normally this
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

What has suspend history actually to do with a selection not available?
your code suspends visibility of the actions run in the history panel?