Every action class has validate
method which checks whether action could be performed in the current context:
var document = context.document;
var copyAction = document.actionsController().actionForID("MSCopyAction");
var pasteAction = document.actionsController().actionForID("MSPasteAction");
if(copyAction.validate()) { // This condition checks whether `copy` action could be performed.
copyAction.performAction(null);
pasteAction.performAction(null); // After performing `copy` action -> data gets into pasteboard immediately.
} else {
print("Selection is empty!");
}
All available actions could be listed using this code snippet:
var document = context.document;
print(document.actionsController().allActions());
In Sketch 44, there're 189 actions 