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.

Revisions

  1. heroheman revised this gist Jun 7, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Add task metadata to current task - Obsidian Templater Script

    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](https://publish.obsidian.md/tasks/Reference/Task+Formats/About+Task+Formats)
  2. heroheman revised this gist Jun 7, 2023. 2 changed files with 21 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions tasks_add_metadata.js β†’ ADD_tasks_metadata.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    <%*
    const format = 'emoji'; // default format
    const format = 'blub'; // default format
    // let metadataType = await tp.system.prompt('Enter the type of metadata (Priority, Repeat, Start, Scheduled, Due, Created, Completion)');
    const metadataTypes = ['priority', 'repeat', 'start', 'scheduled', 'due', 'created', 'completion'];
    const priorityTypes = ['highest', 'high', 'medium', 'low', 'due', 'lowest'];

    @@ -56,27 +57,27 @@
    if (format == 'emoji') {
    switch (metadataType.toLowerCase()) {
    case 'start':
    metadata = `πŸ›« ${dateValue}`;
    metadata = `πŸ›« ${dateValue} `;
    break;
    case 'scheduled':
    metadata = `⏳ ${dateValue}`;
    metadata = `⏳ ${dateValue} `;
    break;
    case 'due':
    metadata = `πŸ“… ${dateValue}`;
    metadata = `πŸ“… ${dateValue} `;
    break;
    case 'created':
    metadata = `βž• ${dateValue}`;
    metadata = `βž• ${dateValue} `;
    break;
    case 'completion':
    metadata = `βœ… ${dateValue}`;
    metadata = `βœ… ${dateValue} `;
    break;
    }
    } else {
    metadata = `[${metadataType}:: ${dateValue}]`;
    metadata = `[${metadataType}:: ${dateValue}] `;
    }
    break;
    default:
    metadata = 'Invalid input';
    metadata = ' ⚠️ Invalid input ';
    }
    tR += metadata + ' ';
    -%>
    12 changes: 12 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -22,5 +22,17 @@ and appends the corresponding tag to the current line of the document.
    It defaults to the [Emoji Format](https://publish.obsidian.md/tasks/Reference/Task+Formats/Tasks+Emoji+Format). You can change the `format` variable in the beginning to something else to use the [DataView Format](https://publish.obsidian.md/tasks/Reference/Task+Formats/Dataview+Format)
    ... and yes, this should be a boolean. Don't @mention me. πŸ€·β€β™‚οΈ

    ## Screenshots
    ![Choose Metadata Type](https://user-images.githubusercontent.com/407485/244006523-fbd5a850-6746-4f2d-8e5c-b58dcf18dcc5.jpg)
    ![Choose Priority](https://user-images.githubusercontent.com/407485/244006662-7c52e067-72a2-4805-8a8f-45b718033734.jpg)
    ![Repeat Frequency](https://user-images.githubusercontent.com/407485/244006795-e20984a5-6590-44b9-a901-26b8cd291c79.jpg)
    ![Date Input](https://user-images.githubusercontent.com/407485/244006862-f96eb07a-aafd-4b1f-b89b-3703c69b8026.jpg)
    ![Example Output in Task](https://user-images.githubusercontent.com/407485/244006916-c2166d39-760a-4676-817c-acb33951d9cc.jpg)






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

  3. heroheman revised this gist Jun 7, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ and appends the corresponding tag to the current line of the document.
    - everything date related, you have several options
    - add a YYYY-MM-DD format
    - leave empty - defaults to today
    - write: `tomorrow`, `today` or `in *n* days`, where n stands for the amount of days in the future
    - write: `tomorrow`, `today` or `in [N] days`, where n stands for the amount of days in the future

    - 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.

  4. heroheman revised this gist Jun 7, 2023. 2 changed files with 25 additions and 3 deletions.
    11 changes: 10 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,21 @@ then prompts them for the appropriate input based on their choice.
    It handles all the types of metadata mentioned [here](https://publish.obsidian.md/tasks/Reference/Task+Formats/About+Task+Formats)
    and appends the corresponding tag to the current line of the document.


    ## Installation
    - You will need the [Templater Plugin](https://github.com/SilentVoid13/Templater)
    - 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.

    ## Usage
    - It first asks for what you want to add
    - Priority lets you choose a priority
    - everything date related, you have several options
    - add a YYYY-MM-DD format
    - leave empty - defaults to today
    - write: `tomorrow`, `today` or `in *n* days`, where n stands for the amount of days in the future

    - 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](https://publish.obsidian.md/tasks/Reference/Task+Formats/Tasks+Emoji+Format). You can change the `format` variable in the beginning to something else to use the [DataView Format](https://publish.obsidian.md/tasks/Reference/Task+Formats/Dataview+Format)
    ... and yes, this should be a boolean. Don't @mention me. πŸ€·β€β™‚οΈ
    17 changes: 15 additions & 2 deletions tasks_add_metadata.js
    Original file line number Diff line number Diff line change
    @@ -39,9 +39,22 @@
    case 'due':
    case 'created':
    case 'completion':
    let dateValue = await tp.system.prompt(`Enter your date for ${metadataType}`);
    // let dateValue = await tp.system.prompt(`Enter your date for ${metadataType}`);
    let dateValue = await tp.system.prompt(`Enter your date for ${metadataType}. You can also write 'today', 'tomorrow' or 'in n days'. Leave empty for today`);
    if (dateValue === '') {
    dateValue = tp.date.now('YYYY-MM-DD'); // use today's date if input is empty
    } else if (dateValue.toLowerCase() === 'today') {
    dateValue = tp.date.now('YYYY-MM-DD'); // use today's date if input is "today"
    } else if (dateValue.toLowerCase() === 'tomorrow') {
    dateValue = tp.date.now('YYYY-MM-DD', 1); // use tomorrow's date if input is "tomorrow"
    } else if (dateValue.toLowerCase().startsWith('in ') && dateValue.toLowerCase().endsWith(' days')) {
    let days = Number(dateValue.split(' ')[1]);
    if (!isNaN(days)) {
    dateValue = tp.date.now('YYYY-MM-DD', days); // use the date in X days if input is "in X days"
    }
    }
    if (format == 'emoji') {
    switch (metadataType) {
    switch (metadataType.toLowerCase()) {
    case 'start':
    metadata = `πŸ›« ${dateValue}`;
    break;
  5. heroheman revised this gist Jun 7, 2023. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -13,3 +13,5 @@ and appends the corresponding tag to the current line of the document.
    It defaults to the [Emoji Format](https://publish.obsidian.md/tasks/Reference/Task+Formats/Tasks+Emoji+Format). You can change the `format` variable in the beginning to something else to use the [DataView Format](https://publish.obsidian.md/tasks/Reference/Task+Formats/Dataview+Format)
    ... and yes, this should be a boolean. Don't @mention me. πŸ€·β€β™‚οΈ

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

  6. heroheman revised this gist Jun 7, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -9,3 +9,7 @@ and appends the corresponding tag to the current line of the document.
    - 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](https://publish.obsidian.md/tasks/Reference/Task+Formats/Tasks+Emoji+Format). You can change the `format` variable in the beginning to something else to use the [DataView Format](https://publish.obsidian.md/tasks/Reference/Task+Formats/Dataview+Format)
    ... and yes, this should be a boolean. Don't @mention me. πŸ€·β€β™‚οΈ

  7. heroheman created this gist Jun 7, 2023.
    11 changes: 11 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    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](https://publish.obsidian.md/tasks/Reference/Task+Formats/About+Task+Formats)
    and appends the corresponding tag to the current line of the document.


    ## Installation
    - You will need the [Templater Plugin](https://github.com/SilentVoid13/Templater)
    - 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.

    69 changes: 69 additions & 0 deletions tasks_add_metadata.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    <%*
    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 + ' ';
    -%>