Here is my setup:
I have different Drafts actions to create anki cards.
This allows me to:
- add content to different decks and notetypes
- add specific tags for organising the Anki notes
- add generic content to Anki notes
Each action has only one step: Callback URL. In my case, the template looks like this:
anki://x-callback-url/addnote?profile=User%201&type=Einfach&deck=Medizin&fldVorderseite=[[title]]&fldR%C3%BCckseite=[[body]]&tags=staging
Everything in bold is user specific for your Anki setup:
- profile
- note type (here: Einfach)
- deck name (here: Medizin)
- first fieldname (here: Vorderseite, for “front side”)
- second fieldname (here R%C3%BCckseite, the encoded form of Rückseite, meaning “back side”
- one or more tags (staging)
Documentation for AnkiMobile’s URL Scheme: URL Schemes - AnkiMobile Manual (it does not work on Anki for Windows/Mac/Linux).
I usually prepare drafts with a first line that is passed into Anki as [[title]] and the remaining content passed into Anki as [[body]].
Every Anki note created from Drafts contains the tag staging, so I can rework these notes in Anki if needed and remove the tag afterwards.
You can add several tags at once:
&tags=staging%20Englisch%20Wortart::Phrase
adds the tags
- staging
- Englisch
- as a hierarchical tag Wortart::Phrase
I only need to remove the tag staging in Anki, every other tagging is done from Drafts.
You can also use Drafts actions to add generic content to your Anki cards. For example, I sometimes stumble across drug trade names I don’t know. So I make a draft containing
Hygroton
chlortalidone
After applying
anki://x-callback-url/addnote?profile=User%201&type=Einfach&deck=Medizin&fldVorderseite=Welcher%20Wirkstoff%20ist%20[[title]]%3f&fldR%C3%BCckseite=[[body]]&tags=staging%20Medizin::Pharmakologie
I get an Anki card prompting me
Which drug is Hygroton? (German: Welcher%20Wirkstoff%20ist%20[[title]]%3f)
with the answer chlortalidone and a pharmacology tag already set.
You can certainly do more with Drafts and Anki. For example, instead of multiple actions with different tags, only one action and a selection list of which tags should be used.
This prompts the user to choose between the types of words and sets the appropriate tag:
// See online documentation for examples
// Scripting | Drafts User Guide
var wortart = [“Adjektiv”, “Adverb”, “Phrase”, “Substantiv”, “Verb”];
var wortart_liste = {“Adjektiv” : “Wortart::Adjektiv”, “Adverb” : “Wortart::Adverb”, “Phrase” : “Wortart::Phrase”, “Substantiv” : “Wortart::Substantiv”, “Verb” : “Wortart::Verb”};
// Prompt
var p = Prompt.create();
p.title = “Tag festlegen”;
p.message = “Wortart auswählen…”;
for (var wortart of wortart) {
p.addButton(wortart);
}
var con = p.show();
if (con) {
var button = p.buttonPressed;
// get matching items from objects
var wortart = wortart_liste[button];
// Create [[tags]] to use in URL step
draft.setTemplateTag(‘tag_wortart’,wortart);
}
else {
context.cancel();
}
Put the above script into a script action and as a second step add the Callback URL
action where tags=[[tag_wortart]]
.
(The script above is based on work by @FlohGro, if I remember correctly. Thanks again.)