Create a Scriptable widget on your iOS home screen
Configure the widget to run the script you created
Script: the one you just created in the Scriptable app
When Interacting: “Run Script”
Parameter: your Supernotes API key
Save the widget and you should be good to go!
Please note: as this is a widget script, it cannot be run directly from within the Scriptable app. You must create a widget on the home screen to run the script.Here’s the example script:
Copy
const widget = await pinnedCardWidget();Script.setWidget(widget);Script.complete();function createCardUrl(cardId) { return `supernotes://card_id=${cardId}`;}async function createCardWidget(card) { const date = new Date(Date.parse(card.data.modified_when)); const dateFormatter = new DateFormatter(); dateFormatter.useMediumDateStyle(); dateFormatter.useShortTimeStyle(); const strDate = dateFormatter.string(date); const gradient = new LinearGradient(); gradient.locations = [0, 1]; gradient.colors = [new Color('#ff607e'), new Color('#ff6682')]; const widget = new ListWidget(); widget.backgroundColor = new Color('#ff6682'); widget.backgroundGradient = gradient; // name const nameElement = widget.addText(card.data.name); nameElement.font = Font.boldSystemFont(16); nameElement.textColor = Color.white(); nameElement.minimumScaleFactor = 0.75; widget.addSpacer(6); // content contentElement = widget.addText(card.data.markup); contentElement.font = Font.mediumSystemFont(12); contentElement.textColor = Color.white(); widget.addSpacer(6); // date modified const footerStack = widget.addStack(); const dateElement = footerStack.addText(strDate); dateElement.font = Font.mediumSystemFont(12); dateElement.textColor = Color.white(); dateElement.textOpacity = 0.8; // open the card directly in Supernotes app when clicking widget.url = createCardUrl(card.data.id); return widget;}async function createErrorWidget(errorText) { const gradient = new LinearGradient(); gradient.locations = [0, 1]; gradient.colors = [new Color('#b92426'), new Color('#ad2527')]; const widget = new ListWidget(); widget.backgroundColor = new Color('#ff6682'); widget.backgroundGradient = gradient; const errorTitleElement = widget.addText('Error'); errorTitleElement.font = Font.boldSystemFont(14); errorTitleElement.textColor = Color.white(); const errorMessageElement = widget.addText(errorText); errorMessageElement.font = Font.mediumSystemFont(12); errorMessageElement.textColor = Color.white(); return widget;}async function pinnedCardWidget() { const req = new Request('https://api.supernotes.app/v1/user/pins'); req.method = 'get'; req.headers = { 'Content-Type': 'application/json', 'Api-Key': args.widgetParameter }; const jsonBody = await req.loadJSON(); if (req.response.statusCode !== 200) { return await createErrorWidget(jsonBody.detail); } const cards = Object.values(jsonBody) if (cards.length === 0) { return await createErrorWidget('No pinned cards'); } return await createCardWidget(cards[0]);}