├── .gitignore ├── README.md └── src ├── appendtodraft.sh ├── opendraft.sh ├── prependtodraft.sh ├── rundraftsaction.sh ├── todraft.sh └── todraftflagged.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Repository: drafts_shell_scripts 2 | 3 | # Description 4 | This repository provides some shell scripts for use with the [Drafts app](https://getdrafts.com) by [@agiletortoise](https://github.com/agiletortoise) on macOS. They allow you to interact with Drafts in some useful ways via the command line. 5 | 6 | # Table of Contents 7 | 8 | - [Description](#description) 9 | - [Table of Contents](#table-of-contents) 10 | - [Installation](#installation) 11 | - [Usage](#usage) 12 | - [Script: `appendtodraft.sh`](#script-appendtodraftsh) 13 | - [Script: `opendraft.sh`](#script-opendraftsh) 14 | - [Script: `prependtodraft.sh`](#script-aprependtodraftsh) 15 | - [Script: `rundraftsaction.sh`](#script-rundraftsactionsh) 16 | - [Script: `todraft.sh`](#script-todraftsh) 17 | - [Script: `todraftflagged.sh`](#script-todraftflaggedsh) 18 | - [Additional Information](#additional-information) 19 | - [Aliases](#aliases) 20 | - [Combined Use Examples](#combined-use-examples) 21 | - [Credits](#credits) 22 | - [License](#license) 23 | - [Legal Disclaimer](#legal-disclaimer) 24 | 25 | # Installation 26 | Available scripts: 27 | 28 | - `appendtodraft.sh` 29 | - `opendraft.sh` 30 | - `prependtodraft.sh` 31 | - `rundraftsaction.sh` 32 | - `todraft.sh` 33 | - `todraftflagged.sh` 34 | 35 | To use the scripts, simply download and copy them to your Mac and set the excutable bit for the scripts using `chmod`. 36 | 37 | All script files can be found in the `src` folder of this repository. 38 | 39 | # Usage 40 | 41 | ## Script: `appendtodraft.sh` 42 | **Description:** 43 | This script accepts content on `STDIN` and a single argument of the UUID of an existing draft. It appends the content to the end of the draft specified by the UUID. 44 | 45 | **Input/Output:** 46 | 47 | | Type | I/O | Data | 48 | |:------:|:------:|:-------------------------------| 49 | | Input | args | UUID of the draft to append to | 50 | | Input | STDIN | Content to append to the draft | 51 | | Output | STDOUT | - None - | 52 | 53 | **Examples:** 54 | Append the content "*lorem ipsum*" to a draft with UUID `B91949F4-F976-4838-AA41-3ECFD752EDC9`. 55 | 56 | ```sh 57 | echo lorem ipsum | ./appendtodraft.sh B91949F4-F976-4838-AA41-3ECFD752EDC9 58 | ``` 59 | 60 | ## Script: `opendraft.sh` 61 | **Description:** 62 | This script accepts a draft UUID on `STDIN`, and will open the draft with the matching UUID in drafts. 63 | 64 | **Input/Output:** 65 | 66 | | Type | I/O | Data | 67 | |:------:|:------:|:-----------| 68 | | Input | args | - None - | 69 | | Input | STDIN | Draft UUID | 70 | | Output | STDOUT | - None - | 71 | 72 | **Examples:** 73 | Open a draft with UUID `B91949F4-F976-4838-AA41-3ECFD752EDC9`. 74 | 75 | ```sh 76 | echo B91949F4-F976-4838-AA41-3ECFD752EDC9 | ./opendraft.sh 77 | ``` 78 | 79 | ## Script: `prependtodraft.sh` 80 | **Description:** 81 | This script accepts content on `STDIN` and a single argument of the UUID of an existing draft. It prepends the content to the start of the draft specified by the UUID. 82 | 83 | **Input/Output:** 84 | 85 | | Type | I/O | Data | 86 | |:------:|:------:|:--------------------------------| 87 | | Input | args | UUID of the draft to prepend to | 88 | | Input | STDIN | Content to prepend to the draft | 89 | | Output | STDOUT | - None - | 90 | 91 | **Examples:** 92 | Prepend the content "*lorem ipsum*" to a draft with UUID `B91949F4-F976-4838-AA41-3ECFD752EDC9`. 93 | 94 | ```sh 95 | echo lorem ipsum | ./prependtodraft.sh B91949F4-F976-4838-AA41-3ECFD752EDC9 96 | ``` 97 | 98 | ## Script: `rundraftsaction.sh` 99 | **Description:** 100 | This script accepts optional text content on `STDIN` and a single argument of the (unique) name of an existing draft action. It runs the specified action, and if any optional text has been specified, this will be used as content for a temporary draft to run the action against. 101 | 102 | **Input/Output:** 103 | 104 | | Type | I/O | Data | 105 | |:------:|:------:|:-------------------------------------------------------| 106 | | Input | args | Name of the Drafts action to run | 107 | | Input | STDIN | Text to set as draft content to run the action against | 108 | | Output | STDOUT | - None - | 109 | 110 | **Examples:** 111 | Run the Drafts action `Action-foo`. 112 | 113 | ```sh 114 | ./rundraftsaction.sh 'Action-foo' 115 | ``` 116 | 117 | Run the Drafts action `Action-bar` against the text "*lorem ipsum*". 118 | 119 | ```sh 120 | echo lorem ipsum | ./rundraftsaction.sh 'Action-bar' 121 | ``` 122 | 123 | ## Script: `todraft.sh` 124 | **Description:** 125 | This script accepts content on `STDIN`, and tags as arguments. It creates a draft with matching content and tags in Drafts. 126 | 127 | **Input/Output:** 128 | 129 | | Type | I/O | Data | 130 | |:------:|:------:|:----------------------------| 131 | | Input | args | Tags to add to new draft | 132 | | Input | STDIN | Content for new draft | 133 | | Output | STDOUT | UUID of newly created draft | 134 | 135 | **Examples:** 136 | Create a draft with content "*lorem ipsum*". 137 | 138 | ```sh 139 | echo lorem ipsum | ./todraft.sh 140 | ``` 141 | 142 | Create a draft with content "*lorem ipsum*" and tags `foo` and `bar`. 143 | 144 | ```sh 145 | echo lorem ipsum | ./todraft.sh foo bar 146 | ``` 147 | 148 | 149 | ## Script: `todraftflagged.sh` 150 | **Description:** 151 | This script accepts content on `STDIN`, and tags as arguments. It creates a draft with matching content and tags in Drafts, that is also marked as flagged. 152 | 153 | **Input/Output:** 154 | 155 | | Type | I/O | Data | 156 | |:------:|:------:|:----------------------------| 157 | | Input | args | Tags to add to new draft | 158 | | Input | STDIN | Content for new draft | 159 | | Output | STDOUT | UUID of newly created draft | 160 | 161 | **Examples:** 162 | Create a flagged draft with content "*lorem ipsum*". 163 | 164 | ```sh 165 | echo lorem ipsum | ./todraftflagged.sh 166 | ``` 167 | 168 | Create a flagged draft with content "*lorem ipsum*" and tags `foo` and `bar`. 169 | 170 | ```sh 171 | echo lorem ipsum | ./todraftflagged.sh foo bar 172 | ``` 173 | 174 | # Additional Information 175 | 176 | ## Aliases 177 | To make these scripts more convenient to work with, I recommend [creating aliases](https://flaviocopes.com/how-to-set-alias-shell/) in your environment. 178 | 179 | Here are the ones I use, with my Drafts scripts being held in a `scripts` folder in my home directory. 180 | 181 | | Alias | Script | Conifguration Command | 182 | |:-------:|:---------------------|------------------------------------------------| 183 | | `a2d` | `appendtodraft.sh` | `alias opd '$HOME/scripts/appendtodraft.sh'` | 184 | | `opd` | `opendraft.sh` | `alias opd '$HOME/scripts/opendraft.sh'` | 185 | | `p2d` | `prependtodraft.sh` | `alias opd '$HOME/scripts/prependtodraft.sh'` | 186 | | `rda` | `rundraftsaction.sh` | `alias opd '$HOME/scripts/rundraftsaction.sh'` | 187 | | `2d` | `todraft.sh` | `alias 2d '$HOME/scripts/todraft.sh'` | 188 | | `2df` | `todraftflagged.sh` | `alias 2df '$HOME/scripts/todraftflagged.sh'` | 189 | 190 | 191 | ## Combined Use Examples 192 | The following examples utilise the aliases above to aid clarity, and provide examples of how you can use multiple scripts together. 193 | 194 | 195 | Create a new draft containing a list of all files (including hidden files) in the current directory and then open the draft in the app. 196 | ``` 197 | ls -a | 2d listing | opd 198 | ``` 199 | 200 | # Credits 201 | **Author:** Stephen Millard (*@sylumer*), [thoughtasylum.com](https://thoughtasylum.com) 202 | 203 | # License 204 | These scripts are **Coffeeware**. You are free to make use of the scripts as long as you like and as much as you like. You owe us nothing. 205 | 206 | But, if you do want to give a little, all development is fuelled by coffee, and you can make a donation to the author's coffee fund. 207 | 208 | Donate A Coffee 209 | 210 | Please also take the time to read the legal disclaimer below. 211 | 212 | # Legal Disclaimer 213 | 214 | These scripts are shared publicly to help others and to contribute back to the wider Drafts community. You may use, and copy these scripts and distribute them with your own projects. For any non-personal sharing or distribution, you are required to provide a reference to this reporistory. This is simply to enable the recipient to keep up to date with any updates that we may make to the original included content. 215 | 216 | Any modifications or derivative works based on any proportion of these scripts, must carry a notice stating that you changed the scripts and should note the date and nature of any such change. Please explicitly acknowledge this repository as the original source of the scripts. 217 | 218 | All scripts are expressly provided "AS IS." WE MAKE NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. WE NEITHER REPRESENTS NOR WARRANT THAT THE OPERATION OF THE CODE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. WE DO NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE CODE. 219 | 220 | You are solely responsible for determining the appropriateness of using the scripts and you assume all risks associated with its use, including but not limited to the risks and costs of errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of operation. This scripts are not intended to be used in any situation where a failure could cause risk of injury or damage to property. 221 | 222 | *Basically, we use these scripts ourselves, we're sharing it publicly so others may benefit, please don't pass the effort put into this off as your own, and while we guarantee nothing regarding use, we really hope that you find it useful in working with the Drafts app, and remember to always keep good backups just in case.* 223 | -------------------------------------------------------------------------------- /src/appendtodraft.sh: -------------------------------------------------------------------------------- 1 | #!/bin/zsh 2 | # Version 1.0.0 3 | # Stephen Millard, ThoughtAsylum.com 4 | 5 | open "drafts5://append?uuid=$1&text=$(