Archives par étiquette : scripts4drafts

Sort draft lines by days

This is a script for Drafts.

This list will be sorted by days:

Tuesday. Chicken
Monday. Pasta
Sunday. Tacos

Script:

// Draft lines are sorted according to the order of the days array
// In each line, the day name must be followed by a dot then a space
// if some lines have no day name, they are placed at the beginning of draft
let days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'].map(d => d + '.');
draft.content = draft.lines.sort(function(a, b) {return days.indexOf(a.split(' ')[0]) - days.indexOf(b.split(' ')[0])}).join('\n');
draft.update();

Published in the Draft directory.

Today Workspace

This is a script for Drafts.

The script allows you to get all drafts with the date of today in the title, within the workspace “Today”.

The date is formatted this way : YYYY-MM-DD.

// first customize the workspace name
let todayWorkspaceName = 'Today';
// script
let workspace = Workspace.find(todayWorkspaceName);
// if you have load of drafts, you can filter them with a tag and uncomment the next line
// workspace.tagFilter = 'today';
workspace.queryString = 'title:' + strftime(new Date(), '%Y-%m-%d');
workspace.update();
app.applyWorkspace(workspace);
app.currentWindow.showDraftList();

Published in the Draft directory.

Create new entry with timestamp

This is a script for Drafts.

This script creates a new entry in the current draft, right after the entry where the cursor is. The new entry includes a timestamp (YYYY-MM-DD-day hh:mm).

By default, the timestamps are sorted by date and time (i.e. in the last entry, it’s the current date and time, but if you insert an entry between two existing one, it’s the date and time of the following one).

The separator between entries is set in the ‘Init’ function.

Published in the Draft directory.

Insert a simple timestamp

This is a script for Drafts.

The timestamp format is simply ‘hh:mm’ and is inserted right at the cursor location.

let loc = editor.getSelectedRange()[0],
  now = new Date().toTimeString().slice(0, 5);
editor.setTextInRange(loc, 0, now);
editor.setSelectedRange(loc + 5, 0);
editor.setSelectedText('');
// activate is not required if the action is launched via a keyboard button
editor.activate();

Published in the Drafts directory.

Go to end of draft

This is a script for Drafts.

let len = draft.content.length;
// if needed, insert a new line at the end of draft
if (!draft.content.endsWith('\n'))
  editor.setTextInRange(len, 0, '\n');
else
  editor.setTextInRange(len, 0, '');
// activate is not required if the action is launched via a keyboard button
editor.activate();

Published in the Drafts directory.

Send text in the cursor line to iOS Reminders, edit it, and move the cursor to the end of edited line

This is a script for Drafts.

let [loc, len] = editor.getSelectedLineRange(),
  str = editor.getTextInRange(loc, len),
  icon = '🔘',
  reminderList = 'Inbox', // 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.notes = new Date().toISOString(); // date or whatever you want
reminder.update();
let newStr = icon + ' ' + str;
editor.setTextInRange(loc, len, newStr);
// 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();

Published in the Drafts directory.