Skip to main content
100%

Add a URL to a text layer

✓ Published0🌍 Public
KKevinGutowski
Last edited Apr 11, 2020
Created on Oct 25, 2019

This example shows how to add hyperlinks to text layers in Sketch by assigning URLs directly to selected text or its active text range. When a user selects one or more text layers and runs the script, it prompts for a URL, then applies that link either to the entire layer or to the specific highlighted portion when text is being edited. The code uses the Sketch JavaScript API, specifically `sketch.getSelectedDocument()`, `layer.sketchObject.addAttribute_value()`, and `UI.getInputFromUser()`, along with `NSLinkAttributeName` and the `textStorage.addAttribute_value_range()` method for formatting range selection. After updating, it reloads the inspector to reflect the changes.

AI-generated description

Similar vizzes