Is it possible to have “Comments” that are ignored in the actual shortcuts draft that the shortcuts are defined in? I tried the default comment syntax of a # symbol for YAML, but it doesn’t seem like it allows expansion. I really just want it to skip over any lines that start with the # symbol; I don’t think this warrants any special algorithms to detect if that symbol is found after the beginning of the line. Essentially:
1 | # This is a comment describing the snippet below
2 | .prj
3 | - Project 1
4 | - Project 2
I want comments so that I can define my shortcuts a bit more descriptively in case I need to go back after a while and recall what it was for modifying the shortcuts. Hope that makes sense!
Nevermind; this was my mistake. Comments work fine!
I just wanted to say thank you for this wonderful shortcut. I had been using TextExpander for my snippets in Drafts, but because I was only using it for Drafts, it didn’t feel like it was worth the monthly charge. I wanted something that would replace it using some automation, and your script exactly fit the bill.
I’ve made a couple of tweaks to your script since installing it. One was just to make it run from a directory of text files in the Drafts /Library directory. That’s really just personal preference: I prefer these kind of configuration files to be outside of my Drafts database. The other I have found really useful is to process the replacements through the draft.processTemplate method. This means I can have a snippet like .ddd: "[[date]]" which expands to today’s date. (I’m not quite sure why, but it only seems to work with the quote marks present.) Thought this second tweak might be something you would be interested in incorporating into your version.
I combined the action you made with this one https://actions.getdrafts.com/a/1IN to be able to use both - defined shortcuts and also placeholders for e.g. names and so on which arent defined as a shortcut.
This is really useful for me because often I write Messages / E-Mails to persons just a few times - and its not neccessary to save their names as a shortcut. The message itself stays the same so this way I have the benefits from both actions!
Another very important point is that I dont want the original template for a message to be replaced with the inserted values, thats why i create a duplicate of the parsed body and the template can be used 100s of times.
If somebody is interested I can share this to the directory, but I just need to make some tweaks for sharing the parsed draft.
Personally I use the Share Action with this script (I didn‘t share it because its not very well developed baut ist works:) ):
var p = Prompt.create();
p.title = "Share draft:";
p.message = "Select an option or cancel if you need the draft later.";
var buttonArray = ["iMessage","WhatsApp","Clipboard","E-Mail"];
for(str in buttonArray)
{
p.addButton(buttonArray[str]);
}
//p.addButton
//p.addButton("iMessage");
//p.addButton("Clipboard");
var didSelect = p.show();
if(didSelect == true)
{
var selection = p.buttonPressed;
if (selection == "iMessage")
{
var msg = Message.create();
msg.body = draft.content;
var result = msg.send();
if (result == true)
{
app.displaySuccessMessage("successfully sent iMessage");
} else
{
app.displayWarningMessage("did not sent the iMessage");
}
} else if (selection == "Clipboard")
{
app.setClipboard(draft.content);
} else if (selection == "E-Mail")
{
var mail = Mail.create();
var mailP = Prompt.create();
mailP.title = "E-Mail Subject";
mailP.message = "select subject for your E-Mail";
mailP.addButton("use custom subject");
mailP.addTextField("custom subject","custom subject","");
mailP.addButton("use title of draft");
var titleIsSubject = 0;
var mailPdidSelect = mailP.show();
if(mailPdidSelect == true)
{
var mailPselection = mailP.buttonPressed;
var subject;
if(mailPselection == "use title of draft")
{
subject = draft.title;
titleIsSubject = 1;
} else if (mailPselection == "use custom subject")
{
subject = mailP.fieldValues["custom subject"];
}
mail.subject = subject;
}
if(titleIsSubject == 1)
{
mail.body = draft.processTemplate("[[body]]");
} else
{
mail.body = draft.content;
}
var result = mail.send();
} else if (selection == "WhatsApp") {
if (device.model == "iPhone") {
app.openURL("whatsapp://send?text=" + encodeURI(draft.content));
} else {
alert("WhatsApp is only possible on iPhone");
context.fail("Share via WhatsApp is not possible on" + device.model + ".");
}
}
}
First off, this action is incredibly useful. Thanks!
So it was inevitable. An action this useful has to go meta and start getting used on code. I have pieces of code that I use a lot and it’s easier to do this quickly. But the following snippet gives unexpected results because it’s interacting with your code. If I break it on purpose, everything comes out just fine.
.split: |
// Quick line split
var text = editor.getText();
text = text.split("\n");
text = text.join(" \n");
editor.setText(text);
Hi there.
I just popped in to say „Huge Thanks“ to @dchar for this and all other contributors.
This is just a beautiful thing - i missed TextExpander since it got subscription and i never fully liked the iOS integration of it anyway.
Off to play with this.
Kind regards and stay safe.
Oh - and a thing i stumbled across:
The first Step inside the Action
const shortcutTag = "shortcuts";
gets overridden inside the „big script“.
I guess its best to comment that line out from the „big one“ and it is easier to edit the „single line“ entry inside of Drafts if one need/wants to change the TAG to react on.
This action does nothing when I run it. At first it threw an error. Fixed that by removing the space after the : in the “shortcuts” draft. Now the action runs successfully but doesn’t replace the text. Very strange. What am I doing wrong?
The “shortcuts” draft uses YAML formatting and can be finicky to start with. Please try to modify your shortcuts draft by adding a hashtag (#) at the beginning of the first line to make it a “comment”:
You fixed it! There was another draft with the “shortcuts” tag and a few snippets defined. When I moved that one to the trash the action started working correctly. Moving the second tagged draft back to the inbox reproduced the error. I thought that multiple drafts with the “shortcuts” tag was okay (one for personal, one for work, etc) but I can live with just one. Having this text expansion action inside of Drafts (including the template engine!), especially now that I’ve assigned a hotkey to it, is magical. Thanks again for the help and for this great action!