Skip to content

Commit

Permalink
Merge pull request #3351 from obsidian-tasks-group/docs-quickadd-and-api
Browse files Browse the repository at this point in the history
docs: Improve the API and QuickAdd pages
  • Loading branch information
claremacrae authored Feb 24, 2025
2 parents cf8cd96 + fd8fc06 commit b99dd19
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 44 deletions.
68 changes: 25 additions & 43 deletions docs/Advanced/Tasks Api.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,54 +67,20 @@ console.log(taskLine);
```

> [!warning]
> This function is returns a `Promise` - always `await` the result!
> This function returns a `Promise` - always `await` the result!
> [!Tip]- Find plugins that use the Tasks API to create tasks
> [Search GitHub for plugins which may use this function](https://github.com/search?q=createTaskLineModal+NOT+is%3Afork+NOT+repo%3Aobsidian-tasks-group%2Fobsidian-tasks+NOT+path%3A*.md&type=code), and by using `createTaskLineModal()`, will fully respect your Tasks settings.
> > [!warning]
> >
> > - You will need to be logged in to GitHub for this search to work.
> > - Not all of these plugins have been reviewed by the Obsidian team: you should search for them in `Settings` > `Community plugins` - or review in [Plugins - Obsidian](https://obsidian.md/plugins) - for safety.
### Usage with QuickAdd
One of the most common usage scenarios is probably in combination with the [QuickAdd](https://github.com/chhoumann/quickadd) plugin
to automatically add tasks to a specific file.

For this you need to enter the following code as the Capture format:

<!-- markdownlint-disable code-fence-style -->
~~~markdown
```js quickadd
return await this.app.plugins.plugins['obsidian-tasks-plugin'].apiV1.createTaskLineModal();
```
~~~
<!-- markdownlint-enable code-fence-style -->

Or if you would like a newline character to be added after your new task line, use this as the Capture format instead:

<!-- markdownlint-disable code-fence-style -->
~~~markdown
```js quickadd
return await this.app.plugins.plugins['obsidian-tasks-plugin'].apiV1.createTaskLineModal() + '\n';
```
~~~
<!-- markdownlint-enable code-fence-style -->

For details refer to [QuickAdd - Inline scripts](https://quickadd.obsidian.guide/docs/InlineScripts).

#### Create the QuickAdd Capture

Use these steps to make the following options appear (tested in QuickAdd 0.12.0):

![Screenshot - Create the QuickAdd Capture](../../images/quickadd-settings-create-capture.png)

1. Open the QuickAdd options.
2. Type the name `Add task` in the `Name` box.
3. Click on the `Template` button and select `Capture`.
4. Click `Add Choice`.

#### Configure the QuickAdd Capture

![Screenshot - Open the QuickAdd Capture Configuration](../../images/quickadd-settings-configure-capture.png)

1. In the new row that was added, click on the cog (⚙) icon.
2. Now fill in the values below. (See above for the code to enter in to the `Capture format` box.)

Screenshot of QuickAdd capture settings (example)
![Screenshot - Edit the QuickAdd Capture Configuration](../../images/api-create-taskline-modal-quickadd-capture-example.png)
See [[QuickAdd#Launching the Edit task modal via QuickAdd|Launching the Edit task modal via QuickAdd]] for full details of how to do this.

## `executeToggleTaskDoneCommand: (line: string, path: string) => string;`

Expand All @@ -130,9 +96,18 @@ const taskLine = '- [ ] This is a task 📅 2024-04-24';

const result = tasksApi.executeToggleTaskDoneCommand(taskLine, sourceFile.path);

// Do whatever you want with the returned value.
// It's just a string containing the Markdown for the toggled task.
console.log(result); // "- [x] This is a task 📅 2024-04-24 ✅ 2024-04-23"
```

> [!Tip]- Find plugins that use the Tasks API to toggle tasks
> [Search GitHub for plugins which may use this function](https://github.com/search?q=executeToggleTaskDoneCommand+NOT+is%3Afork+NOT+repo%3Aobsidian-tasks-group%2Fobsidian-tasks+NOT+path%3A*.md&type=code), and by using `executeToggleTaskDoneCommand()`, will fully respect your Tasks settings.
> > [!warning]
> >
> > - You will need to be logged in to GitHub for this search to work.
> > - Not all of these plugins have been reviewed by the Obsidian team: you should search for them in `Settings` > `Community plugins` - or review in [Plugins - Obsidian](https://obsidian.md/plugins) - for safety.
## Auto-Suggest Integration

> [!released]
Expand Down Expand Up @@ -165,6 +140,13 @@ This can be used, for example, to display the Auto-Suggest on non-task lines. [S
> If the `Editor` is not a `MarkdownView`, the functionality is slightly limited.
> It won't be possible to create [[Task Dependencies]] fields `id` and `dependsOn`.
> [!Tip]- Find plugins that use the Tasks API to suggest task properties
> [Search GitHub for plugins which may use this function](https://github.com/search?q=showTasksPluginAutoSuggest+NOT+is%3Afork+NOT+repo%3Aobsidian-tasks-group%2Fobsidian-tasks+NOT+path%3A*.md&type=code), and by using `showTasksPluginAutoSuggest()`, will fully respect your Tasks settings.
> > [!warning]
> >
> > - You will need to be logged in to GitHub for this search to work.
> > - Not all of these plugins have been reviewed by the Obsidian team: you should search for them in `Settings` > `Community plugins` - or review in [Plugins - Obsidian](https://obsidian.md/plugins) - for safety.
## Limitations of the Tasks API

- Editing tasks:
Expand Down
41 changes: 40 additions & 1 deletion docs/Other Plugins/QuickAdd.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,46 @@ aliases:

## Launching the Edit task modal via QuickAdd

See [[Tasks Api#Usage with QuickAdd]] for how to use the [[Create or edit Task]] modal to add a task.
This section shows how to use QuickAdd with the [[Create or edit Task]] modal to automatically add tasks to a specific file.

For this you need to enter the following code as the Capture format:

````markdown
```js quickadd
return await this.app.plugins.plugins['obsidian-tasks-plugin'].apiV1.createTaskLineModal();
```
````

Or if you would like a newline character to be added after your new task line, use this as the Capture format instead:

````markdown
```js quickadd
return await this.app.plugins.plugins['obsidian-tasks-plugin'].apiV1.createTaskLineModal() + '\n';
```
````

For details refer to [QuickAdd - Inline scripts](https://quickadd.obsidian.guide/docs/InlineScripts).

### Create the QuickAdd Capture

Use these steps to make the following options appear (tested in QuickAdd 0.12.0):

![Screenshot - Create the QuickAdd Capture](../../images/quickadd-settings-create-capture.png)

1. Open the QuickAdd options.
2. Type the name `Add task` in the `Name` box.
3. Click on the `Template` button and select `Capture`.
4. Click `Add Choice`.

### Configure the QuickAdd Capture

![Screenshot - Open the QuickAdd Capture Configuration](../../images/quickadd-settings-configure-capture.png)

1. In the new row that was added, click on the cog (⚙) icon.
2. Now fill in the values below. (See above for the code to enter in to the `Capture format` box.)

Screenshot of QuickAdd capture settings (example)
![Screenshot - Edit the QuickAdd Capture Configuration](../../images/api-create-taskline-modal-quickadd-capture-example.png)

## Creating your own shortcut to build a task

Expand Down

0 comments on commit b99dd19

Please sign in to comment.