Last active
November 15, 2022 06:21
-
-
Save kjaymiller/802ee51de30b67fa84b6ecd61aac4ab3 to your computer and use it in GitHub Desktop.
Craft Quick Save Menu
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
{ | |
"Create New": "", | |
"Apps to Try": "craftdocs://open?blockId=foo&spaceId=bar", | |
"Gifts for 🙋♀️": "craftdocs://open?blockId=baz&spaceId=biz" | |
} |
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
#!/usr/bin/osascript -l JavaScript | |
/* | |
I have two json files with a few lists that I'm always adding links to. I built it in this manner so that I could update the JSON files outside of Keyboard Maestro and use thoss lists in other applications | |
craftLists = Craft docs with lists in them. There is also a _Create New_ option that will create a new document. | |
craftSpaces = List of my spaces. If you use _Create New_. A menu to select a space will follow | |
*/ | |
var app = Application.currentApplication() | |
app.includeStandardAdditions = true | |
var kme = Application('Keyboard Maestro Engine') | |
var craftLists = JSON.parse(kme.getvariable('craftLists')) | |
var craftSpaces = JSON.parse(kme.getvariable('craftSpaces')) | |
function chooseFromList (listName, prompt, defaultObject){ | |
return app.chooseFromList( | |
Object.keys(listName), { | |
withPrompt: prompt, | |
defaultItems: [defaultObject] | |
} | |
)[0]; | |
} | |
var list = chooseFromList( | |
craftLists, 'Choose your List', 'Create New' | |
) | |
let blockId = /(blockId\=)([\w-]+)/; | |
let spaceId = /(spaceId\=)([\w-]+)/; | |
// Instructions for getting Active Tab Name and URL | |
// https://gist.github.com/vitorgalvao/5392178 | |
let safari = Application("Safari"); | |
let url = encodeURIComponent(safari.windows[0].currentTab.url()); | |
let name = encodeURIComponent(safari.windows[0].currentTab.name()); | |
if (list === "Create New"){ | |
var list = chooseFromList( | |
craftSpaces, "Choose a Space", "Personal" | |
) | |
let space = craftSpaces[list].match(spaceId)[2]; | |
`craftdocs://createdocument?spaceId=${space}&title=${name}&content=${url}&folderId=` | |
} | |
else { | |
let block = craftLists[list].match(blockId)[2]; | |
let space = craftLists[list].match(spaceId)[2]; | |
`craftdocs://createblock?parentBlockId=${block}&spaceId=${space}&index=2000&content=${url}` | |
} |
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
{ | |
"Personal": "spaceId=foo", | |
"SharedSpace": "spaceId=bar" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment