Open shortcuts in Script Kit

// Name: Shortcuts
// Description: Shortcut Launcher
// Keyword: sc
import "@johnlindquist/kit";
const DB = home("Library", "Shortcuts", "Shortcuts.sqlite");
let { default: sqlite3 } = await import("sqlite3");
let { open } = await import("sqlite");
const shortcuts_db = await open({ filename: DB, driver: sqlite3.Database });
let query = await shortcuts_db.all(
"SELECT ZNAME,ZACTIONSDESCRIPTION,ZICON,ZBACKGROUNDCOLORVALUE,ZGLYPHNUMBER FROM ZSHORTCUT INNER JOIN ZSHORTCUTICON on ZSHORTCUTICON.Z_PK=ZICON"
);
//Color mappings found https://github.com/atnbueno/Shortcuts-old
const colors = {
4282601983: { RGB: "#F26369", Gradient: "#F36F74 #F2585E" },
4251333119: { RGB: "#FF8567", Gradient: "#FF8E73 #FF7C5C" },
4271458815: { RGB: "#F7A752", Gradient: "#F8AE5F #F7A145" },
4274264319: { RGB: "#E7C640", Gradient: "#E8CA45 #E5C238" },
4292093695: { RGB: "#45C95F", Gradient: "#53CD6B #37C553" },
431817727: { RGB: "#49CBAE", Gradient: "#57CFB4 #2AC7A8" },
1440408063: { RGB: "#51C8DC", Gradient: "#5ACCDE #3FC4D9" },
463140863: { RGB: "#12B4F6", Gradient: "#24BAF7 #00AFF6" },
946986751: { RGB: "#4A69C6", Gradient: "#5874CA #3D5EC2" },
2071128575: { RGB: "#8857C2", Gradient: "#9164C7 #7F4BBE" },
3679049983: { RGB: "#BB7BE4", Gradient: "#C085E6 #B671E2" },
3980825855: { RGB: "#F58BD5", Gradient: "#F694D8 #F583D2" },
255: { RGB: "#87919B", Gradient: "#9099A3 #7E8994" },
3031607807: { RGB: "#95A095", Gradient: "#9DA79D #8D998E" },
2846468607: { RGB: "#9D918C", Gradient: "#A49995 #968984" },
};
// Glyphs names found https://github.com/atnbueno/Shortcuts-old, ChatGPT used to generate emojis
const glyphs = {
59452: "🚗",
61446: "🚗",
61447: "🚗",
59678: "🚌",
61448: "🚌",
61449: "🚋",
61450: "🚇",
59668: "🚲",
59652: "🚑",
59648: "✈ī¸",
59755: "🏠",
59677: "đŸĸ",
59828: "🛒",
61553: "🛍ī¸",
59750: "👜",
59863: "🍴",
59741: "â›Ŋ",
59854: "🌡ī¸",
59845: "☀ī¸",
59782: "🌙",
61517: "🌕",
59835: "❄ī¸",
59714: "☁ī¸",
59715: "🌧ī¸",
59861: "☂ī¸",
59734: "đŸ”Ĩ",
59669: "🔭",
59717: "🧭",
59412: "🌍",
59784: "🏞ī¸",
59733: "🎞ī¸",
59682: "📷",
59402: "đŸŽĨ",
59780: "🎤",
59864: "📹",
59711: "📋",
59681: "📆",
59414: "đŸ’Ŧ",
59403: "đŸ’ŦđŸ’Ŧ",
59779: "đŸ’Ŧ",
59773: "💌",
59774: "đŸ“Ŧ",
59836: "✈ī¸",
61462: "🌐",
59676: "đŸ’ŧ",
61570: "📂",
61571: "📂⚙ī¸",
59719: "đŸ’ŗ",
59865: "⌚",
59814: "📞",
59436: "đŸ’ģ",
59446: "⌨ī¸",
59680: "🧮",
59662: "📊",
59817: "🖨ī¸",
59752: "đŸ’Ŋ",
59722: "đŸ–Ĩī¸",
59519: "đŸ“Ļ",
59826: "🗄ī¸",
59653: "📚",
59721: "🧊",
59851: "đŸ“ē",
59742: "🎮",
59818: "🧩",
61552: "🧩",
59753: "🎧",
61479: "🔘",
61481: "đŸĻģ",
59790: "đŸŽĩ",
59839: "🔊",
61470: "🔊",
61471: "🔊",
61472: "🔇",
61473: "🔊",
61478: "🔊",
61474: "🔊",
59671: "📚",
59465: "📖",
61442: "📕",
59745: "👓",
59788: "đŸŽĢ",
59730: "🎭",
59723: "🎲",
59663: "⚾",
59664: "🏀",
59837: "âšŊ",
59456: "🏈",
59762: "đŸ›ļ",
59756: "🐎",
59712: "🕰ī¸",
59649: "⏰",
59844: "⏱ī¸",
59667: "🔔",
59754: "❤ī¸",
61577: "❤ī¸",
61578: "❤ī¸â¤ī¸",
59841: "⭐",
61579: "⭐",
61581: "✨",
59763: "💡",
59764: "⚡",
59736: "🚩",
59848: "🏷ī¸",
59760: "🔑",
59757: "⌛",
59770: "🔒",
59862: "🔓",
59489: "🔋",
59511: "✨",
59771: "đŸĒ„",
59793: "🖌ī¸",
59798: "✏ī¸",
59794: "📎",
59824: "✂ī¸",
59772: "🔍",
59685: "🔗",
59716: "🎨",
59748: "🔨",
59870: "🔧",
59743: "⚙ī¸",
59825: "đŸĒ›",
59859: "🗑ī¸",
59866: "💧",
59789: "☕",
59827: "👕",
59815: "💊",
59660: "🩹",
59843: "đŸŠē",
61551: "😷",
59657: "⚛ī¸",
59684: "🐱",
59728: "đŸļ",
61554: "đŸģ",
61555: "đŸ¯",
61556: "đŸĩ",
61557: "🐏",
61558: "🐇",
61559: "🐍",
61560: "🐔",
61561: "🐖",
61562: "🐭",
61563: "🐄",
61564: "🐉",
59651: "đŸ‘Ŋ",
61565: "👾",
61566: "🤖",
61567: "đŸ‘ģ",
61568: "💩",
61569: "💀",
59796: "🐾",
59746: "🎓",
59744: "🎁",
59666: "🛏ī¸",
59822: "🚀",
61444: "đŸ—ēī¸",
61452: "📏",
61453: "đŸšĻ",
61454: "🌡ī¸",
61455: "🌐",
61456: "📚",
61573: "📚",
61574: "📚",
61576: "📚",
61457: "📚",
61458: "📚",
61459: "📚",
61460: "📷",
61461: "📝",
61464: "📝",
61465: "📝",
61466: "📝",
61582: "đŸ’Ŧ",
61468: "đŸ’Ŧ",
61475: "🎧",
61476: "🎧",
61477: "🎧",
61480: "đŸ“ģ",
61482: "đŸ“ē",
61483: "🔊",
61484: "🌊",
61486: "📱",
61487: "📱",
61488: "📱",
61489: "📱",
61490: "📱",
61491: "📱",
59806: "â™ŋ",
59801: "đŸšļ",
59800: "đŸšļ‍♂ī¸đŸšļ‍♀ī¸",
59799: "đŸšļ‍♂ī¸đŸšļ‍♀ī¸đŸšļ‍♂ī¸",
59437: "đŸšļ",
59812: "đŸšļ‍♂ī¸",
59808: "🏃",
61493: "🏃",
61494: "🏃",
61495: "🎧",
61496: "🔍",
61532: "🧠",
61533: "🧠",
61534: "😀",
61535: "😄",
61536: "😆",
61537: "😂",
61538: "đŸ¤Ŗ",
61539: "😜",
61540: "đŸ˜Ŧ",
61541: "😍",
61542: "😘",
61543: "😊",
61544: "😎",
61545: "😍",
61546: "🤖",
59751: "🖐ī¸",
61585: "🖐ī¸",
59857: "👍",
61547: "👍",
61548: "✌ī¸",
61549: "🤟",
61550: "👊",
61440: "📲",
59650: "⚠ī¸",
59654: "↩ī¸",
59655: "â†Ēī¸",
59670: "🔖",
59661: "đŸ“Ļ",
59819: "📰",
59508: "â–ļī¸",
59674: "đŸ“Ļ",
59675: "đŸ”ĩ",
59696: "↩ī¸",
59705: "â†Ēī¸",
59693: "âŦ‡ī¸",
59707: "âŦ†ī¸",
59692: "âŦ‡ī¸",
59708: "âŦ†ī¸",
59699: "â–ļī¸",
59704: "âĒ",
59702: "⏸ī¸",
59706: "⏚ī¸",
59695: "⏭ī¸",
59703: "❓",
59690: "✔ī¸",
59700: "➕",
59697: "🔤",
59834: "😊",
61589: "❌",
59725: "📄",
59395: "💲",
59448: "đŸ’ļ",
59512: "ÂŖ",
59514: "ÂĨ",
59515: "â‚ŋ",
59709: "❌",
59656: "*ī¸âƒŖ",
59727: "📄",
59791: "📰",
59739: "🔲",
59392: "â€Ļ",
59445: "📋",
61587: "✅",
59405: "🔲🔲",
59758: "♾ī¸",
59820: "â™ģī¸",
59767: "🔄",
59849: "đŸŽ¯",
59816: "🎙ī¸",
59768: "📍",
59769: "📌",
59795: "đŸ…ŋī¸",
59720: "🌾",
59830: "âŦ†ī¸âŦ‡ī¸",
59786: "↖ī¸â†˜ī¸",
59821: "🔄",
59846: "🔄",
59832: "🔀",
59833: "🎚ī¸",
61583: "đŸ’Ŧ",
59797: "✌ī¸",
59856: "🟡",
59853: "🆎",
61588: "đŸ“Ļ",
59459: "☁ī¸â˜ī¸",
59461: "💊",
59732: "📰",
59497: "📰",
59867: "đŸ“ļ",
61501: "📲",
61497: "đŸšĨ",
61498: "đŸšĨ",
61499: "đŸ“ļ",
61500: "đŸ“ļ",
61502: "đŸŽĩ",
61503: "đŸŽĩ",
61504: "đŸŽĩ",
61505: "đŸŽĩ",
61506: "đŸŽĩ",
61507: "đŸŽĩ",
61508: "đŸŽĩ",
61509: "đŸŽĩ",
61510: "📅",
61511: "📅",
61512: "⏲ī¸",
61513: "⏲ī¸",
61514: "📝",
61515: "📝",
61518: "🌞",
61519: "💡",
61520: "âŦ",
61521: "âĢ",
61522: "📷",
61523: "📷",
61524: "đŸ’ŧ",
61525: "🌅",
61528: "đŸšĢ",
61529: "🔘",
61530: "⭕",
61531: "🔲",
59781: "✍ī¸",
};
let shortcuts = query.map((shortcut) => {
let glyph = glyphs[shortcut.ZGLYPHNUMBER];
let name = shortcut.ZNAME;
let value = shortcut.ZNAME;
let html = `<div class="flex flex-row h-full w-full">
<svg width=48 height=48 class="h-full" style="background-color:${
colors[shortcut.ZBACKGROUNDCOLORVALUE]?.RGB
}"><text x=12 y=36 font-size=24>${glyph}</text></svg>
<div class="flex-1 flex flex-row items-center px-2">${name}</div>
</div>`;
return { name, value, html };
});
let flags = {
view: {
name: "View in Shortcuts",
},
run: {
name: "Run Shortcut",
},
};
let shortcut = await arg(
{ prompt: "Which shortcut would you like to run?", flags },
shortcuts
);
await hide();
if (flag?.view) {
await exec(`/usr/bin/shortcuts view "${shortcut.trim()}"`);
} else {
let result = await exec(`/usr/bin/shortcuts run "${shortcut.trim()}" &`);
if (result?.stdout) await div(md(`## Output:\n\n${result.stdout}`));
}