|
| 1 | +--- |
| 2 | +publish: true |
| 3 | +--- |
| 4 | + |
| 5 | +# Query File Defaults |
| 6 | + |
| 7 | +## Summary |
| 8 | + |
| 9 | +Scenarios: |
| 10 | + |
| 11 | +- You have multiple Tasks queries in a Markdown file, and they have a lot of |
| 12 | + text in common. You would like to avoid repeating those common instructions in |
| 13 | + each one. |
| 14 | +- Usually you like to see your Tasks search results with certain [[Layout]] |
| 15 | + options, but sometimes it is nice to see more detail, perhaps turning |
| 16 | + `show tree` on and off, depending on your mood. |
| 17 | + |
| 18 | +## Applying instructions to every Tasks search in a file |
| 19 | + |
| 20 | +### Obsidian-native User Interface |
| 21 | + |
| 22 | +You can use the Obsidian **File properties** view to customise Tasks searches: |
| 23 | + |
| 24 | + |
| 25 | +<span class="caption">Obsidian's **File properties** widget, with checkboxes and a text box to modify query file defaults for a file containing Tasks searches. See [[#Widening property names in Obsidian]] for the CSS snippet used to widen property names.</span> |
| 26 | + |
| 27 | +To try this out: |
| 28 | + |
| 29 | +1. Show the `File properties` panel: |
| 30 | + - Enable the Obsidian core Properties view plugin: `Settings` > `Core plugins` > turn on `Properties view` |
| 31 | + - Switch to Reading or Live Preview modes. |
| 32 | + - Run the `Properties view: Show file properties` command. |
| 33 | +2. Add one or more `tasks_query_*` properties to the file |
| 34 | + - Click on `Add property`. |
| 35 | + - Start typing `tasks_query_`. |
| 36 | + - Or you can paste in property names from the [[#Supported Query File Defaults property values]] section below. |
| 37 | + - Press `<Return>` or `<Enter>` to add the property. |
| 38 | +3. Now you can modify these `tasks_query_*` properties to change the behaviour of Tasks searches in this file. |
| 39 | + |
| 40 | +> [!info] |
| 41 | +> We plan to streamline the addition of these properties to notes. |
| 42 | +
|
| 43 | +#### Widening property names in Obsidian |
| 44 | + |
| 45 | +By default, the property names are very narrow in Obsidian. |
| 46 | + |
| 47 | +You can make them wider with the following CSS Snippet. |
| 48 | + |
| 49 | +<!-- snippet: resources/sample_vaults/Tasks-Demo/.obsidian/snippets/widen-property-labels.css --> |
| 50 | +```css |
| 51 | +/* Make property labels wider, to fit the names of Tasks-specific properties */ |
| 52 | +.metadata-content { |
| 53 | + --metadata-label-width: 18em; |
| 54 | +} |
| 55 | +``` |
| 56 | +<!-- endSnippet --> |
| 57 | + |
| 58 | +The Obsidian user guide shows how to [use CSS snippets in Obsidian](https://help.obsidian.md/How+to/Add+custom+styles#Use+Themes+and+or+CSS+snippets). |
| 59 | + |
| 60 | +### Meta Bind User Interface |
| 61 | + |
| 62 | +You can use the [Meta Bind](https://obsidian.md/plugins?search=Meta%20Bind) plugin to create a User Interface to easily change your Tasks searches: |
| 63 | + |
| 64 | + |
| 65 | +<span class="caption">Meta Bind widgets to edit Query File Defaults</span> |
| 66 | + |
| 67 | +> [!info]- Set up Meta Bind widgets to edit Query File Defaults |
| 68 | +> Steps to do this, which assume you have already [turned off Obsidian's Restricted mode](https://help.obsidian.md/Extending+Obsidian/Plugin+security): |
| 69 | +> |
| 70 | +> 1. Install and enable [Meta Bind](https://obsidian.md/plugins?search=Meta%20Bind) |
| 71 | +> 2. Click the Copy button to copy the Markdown below. |
| 72 | +> 3. Paste the markdown in to a note in Obsidian that has one or more Tasks searches. |
| 73 | +> 4. Switch to Live Preview or Reading modes, to see the widgets. |
| 74 | +> 5. After experimenting, delete any labels and widgets that you do not need. |
| 75 | +> |
| 76 | +> ![[Meta Bind Query Widgets]] |
| 77 | +
|
| 78 | +## Technical details |
| 79 | + |
| 80 | +### Supported Query File Defaults property values |
| 81 | + |
| 82 | +These are all the properties currently supported by Tasks, as Query File Defaults. |
| 83 | + |
| 84 | +<!-- snippet: DocsSamplesForDefaults.test.DocsSamplesForDefaults_supported-properties-empty.approved.yaml --> |
| 85 | +```yaml |
| 86 | +--- |
| 87 | +tasks_query_explain: |
| 88 | +tasks_query_short_mode: |
| 89 | +tasks_query_show_tree: |
| 90 | +tasks_query_show_tags: |
| 91 | +tasks_query_show_id: |
| 92 | +tasks_query_show_depends_on: |
| 93 | +tasks_query_show_priority: |
| 94 | +tasks_query_show_recurrence_rule: |
| 95 | +tasks_query_show_on_completion: |
| 96 | +tasks_query_show_created_date: |
| 97 | +tasks_query_show_start_date: |
| 98 | +tasks_query_show_scheduled_date: |
| 99 | +tasks_query_show_due_date: |
| 100 | +tasks_query_show_cancelled_date: |
| 101 | +tasks_query_show_done_date: |
| 102 | +tasks_query_show_urgency: |
| 103 | +tasks_query_show_backlink: |
| 104 | +tasks_query_show_edit_button: |
| 105 | +tasks_query_show_postpone_button: |
| 106 | +tasks_query_show_task_count: |
| 107 | +tasks_query_extra_instructions: |
| 108 | +--- |
| 109 | +``` |
| 110 | +<!-- endSnippet --> |
| 111 | + |
| 112 | +> [!tip] |
| 113 | +> We hope in the future to add an Obsidian Command to add all supported Query |
| 114 | +> File Defaults properties to the current file automatically. |
| 115 | +
|
| 116 | +### Types of Query File Defaults property values |
| 117 | + |
| 118 | +These are all the types of properties currently supported by Tasks, as Query |
| 119 | +File Defaults. |
| 120 | + |
| 121 | +> [!tip] |
| 122 | +> We plan to make Tasks add these types to the Obsidian vault automatically in |
| 123 | +> future. |
| 124 | +
|
| 125 | +```json |
| 126 | +{ |
| 127 | + "types": { |
| 128 | + "tasks_query_explain": "checkbox", |
| 129 | + "tasks_query_short_mode": "checkbox", |
| 130 | + "tasks_query_show_tree": "checkbox", |
| 131 | + "tasks_query_show_tags": "checkbox", |
| 132 | + "tasks_query_show_id": "checkbox", |
| 133 | + "tasks_query_show_depends_on": "checkbox", |
| 134 | + "tasks_query_show_priority": "checkbox", |
| 135 | + "tasks_query_show_recurrence_rule": "checkbox", |
| 136 | + "tasks_query_show_on_completion": "checkbox", |
| 137 | + "tasks_query_show_created_date": "checkbox", |
| 138 | + "tasks_query_show_start_date": "checkbox", |
| 139 | + "tasks_query_show_scheduled_date": "checkbox", |
| 140 | + "tasks_query_show_due_date": "checkbox", |
| 141 | + "tasks_query_show_cancelled_date": "checkbox", |
| 142 | + "tasks_query_show_done_date": "checkbox", |
| 143 | + "tasks_query_show_urgency": "checkbox", |
| 144 | + "tasks_query_show_backlink": "checkbox", |
| 145 | + "tasks_query_show_edit_button": "checkbox", |
| 146 | + "tasks_query_show_postpone_button": "checkbox", |
| 147 | + "tasks_query_show_task_count": "checkbox", |
| 148 | + "tasks_query_extra_instructions": "text" |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
0 commit comments