Skip to content

Instantly share code, notes, and snippets.

@heroheman
Last active August 29, 2023 06:16
Show Gist options
  • Save heroheman/1fb19d6fd9ea05a848ecf1fa89ffb8fe to your computer and use it in GitHub Desktop.
Save heroheman/1fb19d6fd9ea05a848ecf1fa89ffb8fe to your computer and use it in GitHub Desktop.
Obsidian Templater Script - add task metadata to current line #obsidian #obsidian-md #obsidian-templater #templater #templater-script #tasks #obsidian-task

This script asks the user which type of metadata they want to insert, then prompts them for the appropriate input based on their choice. It handles all the types of metadata mentioned here and appends the corresponding tag to the current line of the document.

Installation

  • You will need the Templater Plugin
  • Add file to your Templates Folder where Templater is looking for your Templates.
  • In your documents, preferable in with the cursor in a task, press CMD+e (or whatever you call to call the templater template modal) and select the script.

Options

It defaults to the Emoji Format. You can change the format variable in the beginning to something else to use the DataView Format ... and yes, this should be a boolean. Don't @mention me. πŸ€·β€β™‚οΈ

#obsidian #obsidian-md #obsidian-templater #templater #templater-script #tasks #obsidian-task

<%*
const format = 'emoji'; // default format
const metadataTypes = ['priority', 'repeat', 'start', 'scheduled', 'due', 'created', 'completion'];
const priorityTypes = ['highest', 'high', 'medium', 'low', 'due', 'lowest'];
const metadataType = await tp.system.suggester(metadataTypes, metadataTypes, true, 'Select the type of metadata');
let metadata;
switch (metadataType.toLowerCase()) {
case 'priority':
let priorityValue = await tp.system.suggester(priorityTypes, priorityTypes, true, 'Enter your priority');
switch (priorityValue) {
case 'highest':
metadata = format == 'emoji' ? 'πŸ”Ί' : '[priority:: highest]';
break;
case 'high':
metadata = format == 'emoji' ? '⏫' : '[priority:: high]';
break;
case 'medium':
metadata = format == 'emoji' ? 'πŸ”Ό' : '[priority:: medium]';
break;
case 'low':
metadata = format == 'emoji' ? 'πŸ”½' : '[priority:: low]';
break;
case 'lowest':
metadata = format == 'emoji' ? '⏬' : '[priority:: lowest]';
break;
default:
metadata = 'Invalid input';
}
break;
case 'repeat':
let repeatValue = await tp.system.prompt('Enter your repeat frequency');
metadata = format == 'emoji' ? `πŸ” ${repeatValue}` : `[repeat:: ${repeatValue}]`;
break;
case 'start':
case 'scheduled':
case 'due':
case 'created':
case 'completion':
let dateValue = await tp.system.prompt(`Enter your date for ${metadataType}`);
if (format == 'emoji') {
switch (metadataType) {
case 'start':
metadata = `πŸ›« ${dateValue}`;
break;
case 'scheduled':
metadata = `⏳ ${dateValue}`;
break;
case 'due':
metadata = `πŸ“… ${dateValue}`;
break;
case 'created':
metadata = `βž• ${dateValue}`;
break;
case 'completion':
metadata = `βœ… ${dateValue}`;
break;
}
} else {
metadata = `[${metadataType}:: ${dateValue}]`;
}
break;
default:
metadata = 'Invalid input';
}
tR += metadata + ' ';
-%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment