jpencola I agree, and IIRC, we've added that in v43, which is currently in beta.
Why is actions scoped to a per-command level?
matt_sven not sure I'm following, can you elaborate?
ale Actions are at the commands[index].handlers.actions level... but I get it now, I think - it allows for different functions to be called from different scripts.
ale I can't seem to get any of the actions around layer property changes to be called. Any thoughts on why that may be. I've tested with a wildcard * handler and also specific actions like AddShadow but they don't seem to show up in the wildcard or be called explicitly.
WCByrne I'll investigate
WCByrne ok, found the issue. Apparently, the actions are not triggered when using the Inspector, but they are when you use the menus, toolbar buttons or keyboard shortcuts.
That's definitely a bug, and we'll fix that as soon as possible.
ale Thanks for looking into that. It was a bit difficult to discover the actions with incomplete documentation and them not firing as expected.
That said, while I wait, is there any action that will fire when anything about a layer changes?
ale Action request: it would be really useful to have a "ParentChanged" and "SiblingChanged" actions available. I'm working on a couple of plugins that would be greatly simplified (and optimised) if those actions existed...
Seems like SelectionChanged can sometimes be unreliable... testing by quickly selecting between two different layers. The context.actionContext.newSelection sometimes returns an empty array, whereas context.actionContext.document.selectedLayers().layers() returns the correct, actual selection.
Thanks for explaining it Ale.
I have some questions about InsertImage action:
InsertImage actionContext has only action and document properties. Any plans to add to the context any information about inserted image? Actually I'm looking for file URL of the original image, but at least ID of a new MSBitmapLayer might be helpful too.
Seems there is a thing with InsertImage.finish action. I expected that InsertImage.begin is for a time when a user just hit Insert Image menu option and that InsertImage.finish is for a time when selected image inserted. But seems InsertImage.finish happened just after InsertImage.begin. For example, if I hit Insert -> Image -> Cancel, I still get both actions at the console. Could you please check timing?
As I can see for now the action is only for inserting images via Insert -> Image menu. What about drug-and-drop inserted images?
How do you enable wildcard action in Sketch Beta? @ale
According to https://github.com/bomberstudios/sketch-action-api-tester#installation
~/Library/Preferences/com.bohemiancoding.sketch3.plist actionWildcardsAllowed -bool YES
~/Library/Preferences/com.bohemiancoding.sketch3.beta.plist actionWildcardsAllowed -bool YES
Both doesn't work in my experiment.
a dumb idea just to be sure - please check you copy the full command, with defaults write at a beginning:
defaults write ~/Library/Preferences/com.bohemiancoding.sketch3.plist actionWildcardsAllowed -bool YES
besteto Ah yes thanks, I had that when I ran the command. I had that working on my Sketch 43, but now in Sketch 44, the same wildcard method wasn't getting triggered. I think there's definitely changes with Sketch under the hood.
romannurik just ran into this again... Would be really useful for anyone building a design system on Sketch :-)
@ale Same here, I can't get the wildcard action to trigger. Actually - most of the actions listed on http://developer.sketchapp.com/reference/action/ won't trigger. What do I need to do to start using these actions?
Is there an existing action one would recommend for monitoring when the name of an artboard changes? If not, is this an action which could be considered?
Edit and TextChanged seem like decent candidates (based solely on their names) but neither seem to work for detecting if the artboard name has changed.
There are no actions artboard renaming no, and no quick action can be added for that either I'm afraid. We do have some actions for stuff thats user-initiated and immediately finishes, like flipping a layer horizontally. However renaming puts the firstResponder on a textfield and waits for the user to type. This isnt something we can quickly wrap up in an action in our current system, sorry.
So just following this up, should the "Edit" event be working in 46.2? I've got a wildcard listener and not ever seeing an Edit event.