Skip to content

Instantly share code, notes, and snippets.

@KevinGutowski KevinGutowski/actions.js
Last active Jul 30, 2019

Embed
What would you like to do?
Triggering an action in Sketch
// Example
// Thanks to Aby for the idea / inital code nippet
// https://sketchplugins.com/d/201-inserting-a-layer-into-a-document-with-sketch-ux/7
context.document.actionsController().actionForID("MSShowReplaceColorSheetAction").performAction(nil);
// there may be cases where you need to pass in a reference to an object in order for the for the action to work
// here is how you can insert a symbol instance programmatically
// for now let's assume you have a symbol master selected
var symbol = context.selection.firstObject();
try {
var symbolRef = MSSymbolMasterReference.referenceForShareableObject(symbol);
var insertAction = context.document.actionsController().actionForID("MSInsertSymbolAction");
var tempMenuItem = NSMenuItem.alloc().init();
tempMenuItem.setRepresentedObject([symbolRef]);
insertAction.doPerformAction(tempMenuItem);
} catch(e) {
log("Exception: " + e);
}
// List of Actions (as of Version 56 - 81588)
MSInsertVectorAction
MSCurveModeMirroredAction
MSFlipHorizontalAction
MSConstraintResetAction
MSDeleteAction
MSBooleanActionGroup
MSInsertHotspotAction
MSAddFillAction
MSReplaceColorAction
MSAlignLayersCenterAction
MSEditAction
MSMakeLowercaseAction
MSRedoAction
MSCopyCSSAttributesAction
MSFlattenAction
MSShowFillOptionsAction
MSTransformAction
MSCreateSymbolAction
MSInsertSymbolAction
MSMakeUppercaseAction
MSTriangleShapeAction
MSMaskWithShapeAction
MSAutoExpandGroupsAction
MSEditColorSpaceAction
MSListTypeActionNumbered
MSAddInnerShadowAction
MSAlignBottomAction
MSExportSelectionWithExportFormatsAction
MSClosePathAction
MSPasteOverSelectionAction
MSUnderlineAction
MSPrintAction
MSDistributeActions
MSConvertColorSpaceAction
MSRotateAction
MSOffsetPathAction
MSPasteAction
MSNextPageAction
MSAddBorderAction
MSTogglePixelGridAction
MSExportPDFBookAction
MSApplyPortraitOrientationAction
MSZoomToArtboardAction
MSOvalShapeAction
MSToggleAlignmentGuidesAction
MSListTypeActionBullet
MSApplySharedTextStyleAction
MSApplyDataAction
MSCopyCloudDocumentLinkAction
MSRotateCounterclockwiseAction
MSAlignLayersRightAction
MSForceResyncLibraryAction
MSDataMenuAction
MSScaleAction
MSSyncLibraryAction
MSOpenPreviewAction
MSColorInspectorRadialGradientTabAction
MSZoomToActualSizeAction
MSReplaceOverrideStyleAction
MSPasteHereAction
MSToggleRulerDragLockingAction
MSUndoAction
MSToggleLayoutAction
MSCurveModeStraightAction
MSReplaceOverrideSymbolAction
MSSelectAllAction
MSMoveToFrontAction
MSViewDocumentInWelcomeWindowAction
MSConvertSymbolOrDetachInstancesRecursivelyAction
MSCurveModeAsymmetricAction
MSReduceImageSizeAction
MSToggleSelectionAction
MSInsertArtboardAction
MSDefaultStyleAction
MSUnionAction
MSResetSymbolSizeAction
MSChangeFlowAnimationNoAnimationAction
MSLockLayerAction
MSAddExportFormatAction
MSIncompatiblePluginsDisabledAction
MSDistributeVerticallyAction
MSJoinAction
MSRefreshDataAction
MSBackToInstanceAction
MSColorInspectorColorTabAction
MSChangeFlowAnimationFromTopAnimationAction
MSCurveModeDisconnectedAction
MSConvertSymbolOrDetachInstancesAction
MSContextMenuDataAction
MSConstraintPinLeftAction
MSInsertSliceAction
MSBaseAlignLayersAction
Sketch.ToggleLibraryListInComponentsPaneAction
MSToggleLayerHighlightAction
MSMoveUpHierarchyAction
MSRemoveFlowAction
MSIgnoreClippingMaskAction
MSTextOnPathAction
MSToggleFlowInteractionAction
MSAddAsLibraryAction
MSMainMenuDataAction
MSLayerHeightFocusAction
MSReplaceWithSymbolRootAction
MSToggleArtboardShadowAction
MSFindLayerAction
MSToolsMenuAction
MSToggleInterfaceAction
MSAddFlowBackAction
MSViewMenuAction
MSAlignMiddleAction
MSImageOriginalSizeAction
MSCollapseAllGroupsAction
MSPasteStyleAction
MSToggleBorderAction
MSInsertTextLayerAction
MSToggleRulersAction
MSAlignLayersLeftAction
MSConstraintPinTopAction
MSInsertMenuAction
MSCopyStyleAction
MSRemoveUnusedStylesAction
MSReduceFileSizeAction
MSLicenseExpiredAction
MSPolygonShapeAction
MSAlignJustifiedAction
MSToggleFixToViewportAction
MSAlignLayersMiddleAction
MSScissorsAction
MSCutAction
MSColorInspectorModePickerAction
MSRemoveAllOverridesAction
MSMakeLocalFromCloudDocumentAction
MSOpenStyleInLibraryAction
MSAlignRightAction
MSAlignCenterAction
MSPreviousPageAction
MSBooleanMenuAction
MSChangeFlowAnimationFromBottomAnimationAction
MSMoveToBackAction
MSApplySharedLayerStyleAction
MSReplaceImageAction
MSPreviewAtActualSizeAction
MSToggleGridAction
MSExportAction
MSRemoveTextTransformAction
MSDetachSharedStyleAction
MSResetSharedStyleAction
MSLayerWidthFocusAction
MSSmartRotateAction
MSDistributeHorizontallyAction
MSConstraintFixWidthAction
MSShowBorderOptionsAction
MSApplyVerticalFlipAction
MSMoveActionGroup
MSInsertSharedTextAction
MSLayerXFocusAction
MSNewPageAction
MSChangeFontAction
MSDuplicateAction
MSManageShareableObjectsAction
MSZoomInAction
MSUngroupAction
MSZoomAction
MSOpenSymbolInLibraryAction
MSLayoutSettingsAction
MSColorInspectorImageTabAction
MSToggleFillAction
MSCenterSelectionInVisibleAreaAction
MSRemoveSelectedOverridesAction
MSInsertImageAction
MSConvertToOutlinesAction
MSHideAllGridsAndLayoutsAction
MSColorInspectorModeFillTouchBarGroupAction
MSReplaceWithSymbolAction
MSInsertLineAction
MSAlignmentActions
MSFollowFlowAction
MSZoomActions
MSGridSettingsAction
MSAlignLayersBottomAction
MSSaveAsTemplateAction
MSShowLayerListAction
MSMoveToTopAction
MSAssignColorSpaceAction
MSPencilAction
MSRotateClockwiseAction
MSClearDataRecordAction
MSMirrorAction
MSUnlinkFromLibraryAction
MSUpdatePluginsAction
MSStarShapeAction
MSReversePathAction
MSCloudAction
MSClippingMaskAction
MSCopyAction
MSGroupAction
MSAlignTopAction
MSDifferenceAction
MSConstraintPinBottomAction
MSShowReplaceColorSheetAction
MSSendToSymbolsPageAction
MSFlipVerticalAction
MSRenameCloudDocumentAction
MSCenterLayersInCanvasAction
MSReplaceOverrideAction
MSShowColorsAction
MSFlattenSelectionAction
MSViewOnSketchCloudWebAction
MSAlignLeftAction
Sketch.MSTidyAction
MSReplaceFontsAction
MSToggleLayerListVisibilityAction
MSAddFlowAction
MSConstraintPinRightAction
MSShowFontsAction
MSSelectAllArtboardsAction
MSChangeFlowAnimationFromLeftAnimationAction
MSListTypeActionNone
MSRectangleShapeAction
MSApplyHorizontalFlipAction
MSMoveForwardAction
MSGroupActionGroup
MSResizeArtboardToFitAction
MSBaseStyleAction
MSTextStyleTouchBarAction
MSTextAlignTouchBarGroupAction
MSNavigateToOverrideMasterAction
MSCopySVGCodeAction
MSSubtractAction
MSAddShadowAction
MSColorInspectorModeBorderTouchBarGroupAction
MSToggleSliceInteractionAction
MSRenameLayerAction
MSMoveBackwardAction
MSChangeFlowAnimationFromRightAnimationAction
MSShapeAction
MSAlignLayersTopAction
MSChangeInferredLayoutAction
MSHideLayerAction
MSMagnifierAction
MSMakeGridAction
MSSelectAllInArtboardAction
MSRevealInLayerListAction
MSToggleToolbarVisibilityAction
MSConvertFlowToHotspotAction
MSRoundToPixelAction
MSTogglePixelLinesAction
MSUnlinkAndSyncFromLibraryAction
MSIntersectAction
MSLayerFocusActions
MSResetOriginAction
MSLayerYFocusAction
MSManageCloudDocumentShareSettingsAction
MSConstraintFixHeightAction
MSCopyOverrideAction
MSApplyLandscapeOrientationAction
MSRoundedRectangleShapeAction
MSColorInspectorLinearGradientTabAction
MSAddFlowHomeAction
MSToggleInspectorVisibilityAction
MSClippingMaskModeAction
MSInsertArrowAction
MSBadgeMenuAction
MSZoomOutAction
MSColorInspectorCircularGradientTabAction
MSSyncLocalStyleAction
MSShowComponentsPaneAction
MSCurveModeTouchGroupAction
MSZoomToSelectionAction
MSCreateSharedStyleAction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.