Last active
April 13, 2021 13:04
-
-
Save KevinGutowski/60719f699472bb496f813525398d4b6d to your computer and use it in GitHub Desktop.
Triggering an action in Sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 71 - 115107) | |
| /* | |
| let actions = context.document.actionsController().allActions() | |
| let actionStrings = [] | |
| for (let i=0;i<actions.length;i++) { | |
| actionStrings.push(actions[i].className()) | |
| } | |
| let string = actionStrings.join('\n') | |
| let path = '/Users/kgutowski/Downloads/output.txt' | |
| NSString.alloc().initWithString(string).writeToFile_atomically(path,true) | |
| */ | |
| MSInsertVectorAction | |
| MSPresenceSignInAction | |
| MSCurveModeMirroredAction | |
| MSFlipHorizontalAction | |
| MSConstraintResetAction | |
| MSDeleteAction | |
| MSBooleanActionGroup | |
| MSInsertHotspotAction | |
| Sketch.MSInsertComponentInstanceAction | |
| MSPresenceFollowingAction | |
| MSViewDocumentInDocumentsWindowAction | |
| MSAddFillAction | |
| MSReplaceColorAction | |
| MSAlignLayersCenterAction | |
| MSEditAction | |
| Sketch.MSComponentsPickerAction | |
| MSAssistantCheckDocumentAction | |
| MSMakeLowercaseAction | |
| MSRedoAction | |
| MSCopyCSSAttributesAction | |
| MSFlattenAction | |
| MSShowFillOptionsAction | |
| MSLegacyInsertMenuAction | |
| MSTransformAction | |
| MSAssistantConfigureAction | |
| MSCreateSymbolAction | |
| MSInsertSymbolAction | |
| MSMakeUppercaseAction | |
| MSTriangleShapeAction | |
| MSMaskWithShapeAction | |
| MSAutoExpandGroupsAction | |
| MSPasteWithStyleAction | |
| MSPresenceDisabledAction | |
| MSAssistantInstallFromURLAction | |
| MSEditColorSpaceAction | |
| MSListTypeActionNumbered | |
| MSAddInnerShadowAction | |
| MSAlignBottomAction | |
| MSExportSelectionWithExportFormatsAction | |
| MSClosePathAction | |
| MSPasteOverSelectionAction | |
| MSUnderlineAction | |
| MSExportPatchesAction | |
| MSPrintAction | |
| MSDistributeActions | |
| MSConvertColorSpaceAction | |
| MSRotateAction | |
| MSOffsetPathAction | |
| MSPasteAction | |
| MSNextPageAction | |
| MSAddBorderAction | |
| MSTogglePixelGridAction | |
| MSExportPDFBookAction | |
| MSApplyPortraitOrientationAction | |
| MSZoomToArtboardAction | |
| MSOvalShapeAction | |
| MSToggleAlignmentGuidesAction | |
| MSListTypeActionBullet | |
| MSApplySharedTextStyleAction | |
| MSPresencePersonalSpaceAction | |
| MSOrganizeImportedSymbolsAction | |
| MSApplyDataAction | |
| MSCopyCloudDocumentLinkAction | |
| MSPresenceAction | |
| MSRotateCounterclockwiseAction | |
| MSAlignLayersRightAction | |
| MSForceResyncLibraryAction | |
| MSDataMenuAction | |
| MSScaleAction | |
| MSColorInspectorRadialGradientTabAction | |
| MSOpenPreviewAction | |
| MSSyncLibraryAction | |
| Sketch.MSVisitSymbolComponentAction | |
| MSZoomToActualSizeAction | |
| MSReplaceOverrideStyleAction | |
| MSPasteHereAction | |
| Sketch.MSRenameSharedStyleAction | |
| MSToggleRulerDragLockingAction | |
| MSUndoAction | |
| MSPresenceCollaboratingAction | |
| MSToggleLayoutAction | |
| MSCurveModeStraightAction | |
| MSReplaceOverrideSymbolAction | |
| MSSelectAllAction | |
| MSMoveToFrontAction | |
| MSDelayOutgoingPatchAction | |
| MSConvertSymbolOrDetachInstancesRecursivelyAction | |
| MSCurveModeAsymmetricAction | |
| MSReduceImageSizeAction | |
| MSToggleSelectionAction | |
| MSInsertArtboardAction | |
| MSAssistantShowIgnoredAction | |
| MSAssistantActivateAction | |
| MSDefaultStyleAction | |
| MSUnionAction | |
| MSResetSymbolSizeAction | |
| MSChangeFlowAnimationNoAnimationAction | |
| MSLockLayerAction | |
| MSAddExportFormatAction | |
| MSIncompatiblePluginsDisabledAction | |
| MSDistributeVerticallyAction | |
| MSJoinAction | |
| MSRefreshDataAction | |
| MSBackToInstanceAction | |
| MSColorInspectorColorTabAction | |
| MSCurveModeDisconnectedAction | |
| MSChangeFlowAnimationFromTopAnimationAction | |
| MSConvertSymbolOrDetachInstancesAction | |
| MSContextMenuDataAction | |
| MSConstraintPinLeftAction | |
| MSInsertSliceAction | |
| MSBaseAlignLayersAction | |
| MSFindAction | |
| Sketch.MSRevealComponentsPanelAction | |
| MSToggleLayerHighlightAction | |
| MSMoveUpHierarchyAction | |
| MSRemoveFlowAction | |
| MSIgnoreClippingMaskAction | |
| MSTextOnPathAction | |
| MSToggleFlowInteractionAction | |
| MSAddAsLibraryAction | |
| MSMainMenuDataAction | |
| MSAssistantCheckDocumentAutomaticallyAction | |
| MSLayerHeightFocusAction | |
| MSReplaceWithSymbolRootAction | |
| MSToggleArtboardShadowAction | |
| MSImportPatchesAction | |
| MSShowDocumentFontsAction | |
| MSToggleInterfaceAction | |
| MSToolsMenuAction | |
| Sketch.MSContentModeAction | |
| MSAddFlowBackAction | |
| MSViewMenuAction | |
| MSAlignMiddleAction | |
| MSImageOriginalSizeAction | |
| MSCollapseAllGroupsAction | |
| MSPasteStyleAction | |
| MSToolbarNotificationAction | |
| Sketch.MSChangeLayerStyleComponentKindAction | |
| MSToggleBorderAction | |
| MSInsertTextLayerAction | |
| MSToggleRulersAction | |
| MSAlignLayersLeftAction | |
| Sketch.MSCopyComponentAction | |
| MSConstraintPinTopAction | |
| MSInsertMenuAction | |
| MSCopyStyleAction | |
| MSRemoveUnusedStylesAction | |
| Sketch.MSMaintainScrollPositionAction | |
| MSReduceFileSizeAction | |
| MSLicenseExpiredAction | |
| Sketch.MSChangeSymbolComponentKindAction | |
| Sketch.MSChangeSwatchComponentKindAction | |
| MSPolygonShapeAction | |
| MSOpenSwatchInLibraryAction | |
| MSDelayIncomingPatchAction | |
| MSAlignJustifiedAction | |
| MSToggleFixToViewportAction | |
| MSAlignLayersMiddleAction | |
| MSScissorsAction | |
| MSCutAction | |
| MSColorInspectorModePickerAction | |
| MSRemoveAllOverridesAction | |
| MSOpenStyleInLibraryAction | |
| MSAlignRightAction | |
| MSAlignCenterAction | |
| MSPreviousPageAction | |
| MSInsertDataAsLayerAction | |
| MSBooleanMenuAction | |
| MSExportLimitsAction | |
| Sketch.MSEditSymbolMasterComponentAction | |
| MSChangeFlowAnimationFromBottomAnimationAction | |
| MSMoveToBackAction | |
| MSApplySharedLayerStyleAction | |
| MSReplaceImageAction | |
| MSPreviewAtActualSizeAction | |
| MSToggleGridAction | |
| MSExportAction | |
| Sketch.MSChangeComponentKindActionGroup | |
| MSPresenceAvatarAction | |
| MSRemoveTextTransformAction | |
| MSOpenTypeFeaturesAction | |
| MSDetachSharedStyleAction | |
| MSResetSharedStyleAction | |
| MSLayerWidthFocusAction | |
| MSSmartRotateAction | |
| MSDistributeHorizontallyAction | |
| MSConstraintFixWidthAction | |
| MSShowBorderOptionsAction | |
| MSApplyVerticalFlipAction | |
| Sketch.ToggleLibraryListInComponentsPanelAction | |
| MSMoveActionGroup | |
| MSInsertSharedTextAction | |
| MSLayerXFocusAction | |
| MSNewPageAction | |
| MSChangeFontAction | |
| MSDuplicateAction | |
| MSZoomInAction | |
| MSUngroupAction | |
| MSZoomAction | |
| MSOpenSymbolInLibraryAction | |
| Sketch.MSTogglePresenceNamesAction | |
| MSColorInspectorImageTabAction | |
| MSLayoutSettingsAction | |
| MSToggleFillAction | |
| MSCenterSelectionInVisibleAreaAction | |
| MSRemoveSelectedOverridesAction | |
| MSInsertImageAction | |
| MSAssistantInstallFromDiskAction | |
| MSConvertToOutlinesAction | |
| MSHideAllGridsAndLayoutsAction | |
| MSColorInspectorModeFillTouchBarGroupAction | |
| MSReplaceWithSymbolAction | |
| MSInsertLineAction | |
| MSAlignmentActions | |
| MSFollowFlowAction | |
| MSZoomActions | |
| MSGridSettingsAction | |
| MSAlignLayersBottomAction | |
| MSSaveAsTemplateAction | |
| MSShowLayerListAction | |
| MSMoveToTopAction | |
| MSAssignColorSpaceAction | |
| MSPencilAction | |
| MSRotateClockwiseAction | |
| MSToggleSidebarVisibilityAction | |
| Sketch.MSAddComponentAction | |
| MSClearDataRecordAction | |
| MSMirrorAction | |
| MSUnlinkFromLibraryAction | |
| MSUpdatePluginsAction | |
| MSStarShapeAction | |
| MSReversePathAction | |
| Sketch.MSChangeTextStyleComponentKindAction | |
| MSCloudAction | |
| Sketch.MSTogglePresenceCursorsAction | |
| MSClippingMaskAction | |
| MSCopyAction | |
| MSGroupAction | |
| MSAlignTopAction | |
| MSDifferenceAction | |
| MSConstraintPinBottomAction | |
| MSSearchAction | |
| MSShowReplaceColorSheetAction | |
| MSSendToSymbolsPageAction | |
| MSFlipVerticalAction | |
| MSCenterLayersInCanvasAction | |
| MSReplaceOverrideAction | |
| MSShowColorsAction | |
| MSFlattenSelectionAction | |
| MSViewOnSketchCloudWebAction | |
| MSAlignLeftAction | |
| Sketch.MSTidyAction | |
| MSPresenceSaveToCloudAction | |
| MSReplaceFontsAction | |
| MSShowFontsAction | |
| MSAddFlowAction | |
| MSConstraintPinRightAction | |
| MSSelectAllArtboardsAction | |
| MSChangeFlowAnimationFromLeftAnimationAction | |
| MSListTypeActionNone | |
| MSRectangleShapeAction | |
| MSApplyHorizontalFlipAction | |
| MSMoveForwardAction | |
| MSGroupActionGroup | |
| MSResizeArtboardToFitAction | |
| MSBaseStyleAction | |
| MSTextStyleTouchBarAction | |
| MSTextAlignTouchBarGroupAction | |
| MSNavigateToOverrideMasterAction | |
| MSCopySVGCodeAction | |
| Sketch.MSRenameComponentAction | |
| MSSubtractAction | |
| MSAddShadowAction | |
| MSColorInspectorModeBorderTouchBarGroupAction | |
| MSToggleSliceInteractionAction | |
| MSRenameLayerAction | |
| MSMoveBackwardAction | |
| MSShapeAction | |
| MSAlignLayersTopAction | |
| MSChangeFlowAnimationFromRightAnimationAction | |
| MSChangeInferredLayoutAction | |
| MSHideLayerAction | |
| MSMagnifierAction | |
| MSMakeGridAction | |
| MSAssistantInstallMissingAction | |
| MSRevealInLayerListAction | |
| MSToggleToolbarVisibilityAction | |
| MSConvertFlowToHotspotAction | |
| MSRoundToPixelAction | |
| Sketch.MSSaveAndStarVersionAction | |
| MSTogglePixelLinesAction | |
| MSUnlinkAndSyncFromLibraryAction | |
| MSIntersectAction | |
| MSLayerFocusActions | |
| MSResetOriginAction | |
| MSLayerYFocusAction | |
| MSManageCloudDocumentShareSettingsAction | |
| Sketch.MSRevealComponentAction | |
| MSConstraintFixHeightAction | |
| MSEmbedFontsForCloudAction | |
| MSCopyOverrideAction | |
| MSAssistantAction | |
| MSApplyLandscapeOrientationAction | |
| MSRoundedRectangleShapeAction | |
| MSColorInspectorLinearGradientTabAction | |
| MSAddFlowHomeAction | |
| MSToggleInspectorVisibilityAction | |
| MSClippingMaskModeAction | |
| MSInsertArrowAction | |
| MSBadgeMenuAction | |
| MSZoomOutAction | |
| MSColorInspectorCircularGradientTabAction | |
| MSSyncLocalStyleAction | |
| MSShowComponentsPaneAction | |
| MSCurveModeTouchGroupAction | |
| MSZoomToSelectionAction | |
| Sketch.MSDuplicateComponentAction | |
| MSCreateSharedStyleAction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment