Automators 55: Drafts with Agile Tortoise

2 Likes

Not in my Overcast feed yet.

Is it already posted?

It should be appearing soon. I’ve just been chatting to @RosemaryOrchard about it being in the RSS, but not yet appearing in some of the other service feeds.

1 Like

Thank you for informing her.

I just received the notification from Overcast for this new episode.

I had a couple of ideas about the playing a sound in a Drafts action point that came up.


Audio (JavaScript)

I tried creating an approach using JavaScript, but frustratingly, it only seems to work for me on the Mac, and not on the iPhone or iPad (running iOS/iPadOS 13 at least), and I didn’t see any obvious reason why it shouldn’t work on all platforms just the same - then I came across this.

And no IBM don’t provide a workaround in their document, only confirmation that there isn’t one.

But if you have a Mac, you can certainly try it out, and see if you can identify what the mystery sound it plays is :wink:


Audio (Shell Script)

But, if you’re on a Mac anyway, I think a nicer approach, assuming you have the audio file stored locally, is to use Drafts to run some shell script to play the audio.

This action is just playing a standard Mac system audio file from the command line and it’s actually really easy to do.


In both cases the actual audio to be played is specified by the template tag step at the start of the action, so if anyone does want to use it, it is relatively easy to maintain (but that first option uses a Base64 encoded version of an MP3 file - you can encode files on the command line on the Mac (see the “Base64 Encoding Images: Mac” section in this Drafts-related post) or via an online service, of which there are many).

To use these actions, you can include the action at the end of any other action to play a sound on completion.


Note: I’ve purposefully left the options for both actions as visible on Mac and iPhone/iPad just so people can take a look at the steps an code regardless of what platforms they have access to.


1 Like

@MacSparky level 100 fanboyed in this one! lol

2 Likes

There was a mention of automatically turning off the sleep mode on the iPhone while shopping. How was this achieved?

Put this in a JavaScript action:

app.isIdleDisabled = true;

Thanks. Can this be used in Scriptable or only in Drafts?

This is an attribute specifically on the “app” global in Drafts so I’m thinking it’s just drafts.

1 Like

You are correct. It is a Drafts specific feature. App developers would need to build an equivalent into their apps for it to be available in those apps.

The shopping mode action is linked in the show notes :slight_smile:

1 Like

Thanks. That would be a good Shortcut action to have. Disable and Enable Auto-Luck when a certain app is open.

I’m pretty sure you have to have Drafts active for it to work.

Yes. I was just wishfull thinking that the Shortcuts had a stock action like that. It would be useful.

I hear ya. Lots of settings would be handy if we could toggle them with Shortcuts :confused:

What happened to the Save Note and Send Tasks to OmniFocus Drafts shortcut, by @RosemaryOrchard? The link is no longer valid.

4 Likes

@MacSparky , I could not be sure it is what you described in the episode but How can I add a template text infront of my draft text?

With using insert text action it only add where the cursor is.

Simply, writing a note and with taping an action to add a title and date infront of it and a checklist in the end if my note?

@nenver, there are lots of ways to create actions to do this. Here’s one example I put together for you:

The action has 4 steps.

1. Prompt

This step prompts you to enter a title for the draft to add at the top. If you always want the same title, you would just put it into step two and delete this step.

2. Define ‘start’ tag

Drafts has a few things it refers to as “tags”. This action step is referring to a template tag and can be thought of as a variable, a place to hold some content we can use later.

You edit this like a mini draft and can use text, Markdown, template tags, etc.

I’ve set it up to put whatever was entered in the first action step (the prompt) as a level 1 Markdown heading. This is followed on the next line with a Markdown bolded “Date:” label, followed by the date - you can apply further formatting to the date by modifying the tag.

It then adds a blank line at the end.

# [[thetitle_text]]
**Date:** [[date]]  

You can modify this to whatever you want to appear at the start of the draft it is run against.

3. Define ‘end’ tag

The ‘end’ tag is the same sort of thing but for the end.

As an example, I added a horizontal rule, followed by some example checkboxes.


---

- [ ] Checklist Item 1
- [ ] Checklist Item 2
- [ ] Checklist Item 3

4. Update draft content

The final step is a few lines of JavaScript to say update the content of the draft to be the content associated with the start tag, followed by the current draft content, followed by the content associated with the end tag.

draft.content = draft.processTemplate(`[[start]]
[[draft]]
[[end]]`);
draft.update();

Should you, or anyone else want to try something a little different.

If you wanted to get more advanced and do things like maintaining the cursor position/selection, then perhaps check out the editor.TA_prepend() and the editor.TA_append() functions in the ThoughtAsylum Drafts Library, which you can get by installing and setting up the ThoughtAsylum action group; as the first step of your action, include action TAD as the first action step, and this will load the library and give you access to those functions in a script step.

Hope that helps.

2 Likes

@RosemaryOrchard, Bumping @Drewster post: the link for the “save notes and send actions to OF” action is broken…

1 Like