The “Send line to iOS Reminders” action created by @scripts4drafts is my starting point.
I’m hoping someone can tweak that script to do the following…
- Instead of defining the Reminders list in the script, take the [[title]] of the draft and use that as the name of the list in Reminders (creating it if it doesn’t exist)
- Insert the [[title]] of the draft into the first row of the notes field in the generated reminder
- Insert the [[draft_open_url]] below the [[title]]. (Bonus if it contains the code to populate the URL field in the upcoming iOS 13 reminders app)
- In the draft, assume that all of the lines to be processed start with “[ ]” and when this script is run, insert an “O”, so the result of the processed line is “[O]”
I’ve assembled some interesting things with URL schemes and Shortcuts, but nothing approaching the above.
Thank you,
John
Have you tried doing any of this yourself? You’re referencing tags and a clear step by step approach. On that basis, it seems like something you could definitely have a go at yourself; and then if you have particular issues come back with those.
If you have had a go, I assume you must already have hit some issues. In that case it would be worth sharing what you have and the issue(s) you have encountered.
1 Like
Ok… this part is working as expected…
reminderList = draft.title, // pick the Reminders list you want
list = ReminderList.findOrCreate(reminderList),
… working on it.
reminder.notes = draft.title
I can get that, but what is the reference for the open url? And then, how do I insert it on the next line?
And, then I don’t know how to…
- Get rid of the “[ ]” in the reminder title, and…
- Replace the "[ ] in the draft with “[O]”
Okay. I’ve put together a few code examples for you that should help you figure these out. The comments should help explain what is going on, but otherwise just track which alert is which as the code runs as they just display various results one after the other.
//Display the hyperlink for the current draft
alert(draft.permalink);
//Create a single unchecked line
let strTemp = "[ ] foo";
alert(strTemp);
//Replace the uncheck with an "O" based check
alert(strTemp.replace("[ ]", "[O]"));
//Add another unchecked line
strTemp += "\n[ ] bar";
alert(strTemp);
//Try the same replace as before
//It only replaces the first instance so this replace is only going to work if we go line by line
alert(strTemp.replace("[ ]", "[O]"));
//If we use a regular expression, we can change all occurrences
alert(strTemp.replace(/\[ \]/g, "[O]"));
//Add another unchecked line with a mid-line uncheck
strTemp += "\n[ ] quz & another [ ] on the same line";
alert(strTemp);
//If we want to replace all, it will get the mid line too
alert(strTemp.replace(/\[ \]/g, "[O]"));
//If we only want the start of the line we change the regular expression
alert(strTemp.replace(/^\[ \]/mg, "[O]"));
Keep in mind that removing text is logically the same as replacing it with a text string of zero length.
1 Like
I was able to get this: reminder.notes = draft.title + “\n” + draft.permalink;
Thank you.
But I still don’t know what to do with the rest. I don’t know where to plug in strTemp.replace(/[ ]/g, “[O]”)); (which I think is the solution I’m after).
Any more tips?
Well I don’t exactly understand where you want this to go from your description as there is some ambiguity there.
If you want to do some processing with the content and send it on, use it as is, and use strTemp
where you need it. Otherwise perhaps this at the end?
draft.content = draft.content.replace(/[ ]/g, "[O]"));
draft.update();
1 Like
Assuming loc, len and str are set at the beginning of the “Send line to iOS Reminders” script, try this to edit the current line:
editor.setTextInRange(loc, len, str.replace(/\[ \]/, “[O]”));
1 Like
Thank you, @sylumer and @scripts4drafts.
Got it. Here’s the result.
let [loc, len] = editor.getSelectedLineRange(),
str = editor.getTextInRange(loc, len),
icon = '[ ]',
reminderList = draft.title, // pick the Reminders list you want
list = ReminderList.findOrCreate(reminderList),
reminder = list.createReminder();
reminder.title = str.trim(); // trim gets rid of end of line (\n), if any
// -
reminder.title = str.replace(/\[ \] /,"");
// -
reminder.notes = draft.title + "\n" + draft.permalink;
reminder.update();
newStr = icon + ' ' + str;
editor.setTextInRange(loc, len, str.replace(/\[ \]/, "[O]"));
// move the cursor to the end of the edited line
editor.setSelectedRange(loc + newStr.trim().length, 0);
editor.setSelectedText('');
// activate is not required if the action is launched via a keyboard button
editor.activate();
1 Like
Note that icon is no more useful in your script and newStr should be updated. I tweaked a little:
let [loc, len] = editor.getSelectedLineRange(),
str = editor.getTextInRange(loc, len),
newStr = str.trim(), // trim gets rid of end of line (\n), if any
list = ReminderList.findOrCreate(draft.title),
reminder = list.createReminder();
reminder.title = newStr.replace(/\[ \] /, '');
reminder.notes = draft.title + '\n' + draft.permalink;
reminder.update();
editor.setTextInRange(loc, len, str.replace(/\[ \]/, '[O]'));
// move the cursor to the end of the edited line
editor.setSelectedRange(loc + newStr.length, 0);
editor.setSelectedText('');
// activate is not required if the action is launched via a keyboard button
editor.activate();
1 Like