Skip to content

Instantly share code, notes, and snippets.

@shabegom
Last active July 5, 2023 23:33
Show Gist options
  • Save shabegom/e40e61a55c8ae333fe8d2d3fa3e8ec1e to your computer and use it in GitHub Desktop.
Save shabegom/e40e61a55c8ae333fe8d2d3fa3e8ec1e to your computer and use it in GitHub Desktop.
Scriptable (iOS) Script for running a Tana QuickAdd Shortcut
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: green; icon-glyph: magic;
/*
SETUP INTSTRUCTIONS
0. Install the Tana QuickAdd Shortcut: https://www.icloud.com/shortcuts/74ce7f48d6d5493c8c0ba563c5f040d6
1. In Tana, Create a Node where you'd like quick added nodes to go.
- quick added nodes will appear as children of this one
- I put mine off my workspace root
- you can reference this node in your #day supertag if you want quickcaptures to show up in the daily nodes
2. With the cursor on that node, Open the command line and select "Get API Token".
- This doesn't work in Safari, so make sure you're using Chrome.
3. Paste the token in the Dictionary in the shortcut with the key nodeToken
4. Make sure you have Scriptable installed. Add this script to your Scriptable folder in iCloud
CURRENT ISSUES
- adding tags currently does not work. Any tags added will be stripped from the output in Tana
*/
const inputArgs = args.shortcutParameter
if (!inputArgs) {
error("Tana QuickAdd was triggered with not input arguments")
}
const token = inputArgs.nodeToken
if (!token) {
error("Need to provide API Token")
}
const content = inputArgs.node;
if (!content) {
error("no input provided to Tana QuickAdd")
}
const encodedContent = encodeURI(content)
const url = `https://europe-west1-tagr-prod.cloudfunctions.net/addToNode?note=${encodedContent}`;
await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + token,
"Content-Type": "application/json",
},
})
.then((response) => {
Script.complete()
})
.catch((error) => {
error(`Error sending node: ${error}`)
});
// UTILITY FUNCTIONS
function fetch(url, params = {}) {
const req = new Request(url);
req.method = params.method || "GET";
req.body = params.body;
req.headers = params.headers || {};
return req.load();
}
function error(err) {
console.log(`Error: ${err}`);
const errAlert = new Notification()
errAlert.body = err
errAlert.schedule()
Script.complete()
}
function notice(note) {
const notice = new Notification()
notice.body = note
notice.schedule()
}
@CooperHash
Copy link

i wonder if api to fetch tana task(to do list), and i want to use it to remind me with iphone notification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment