Archives par étiquette : scripts

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.

Track time v2

This is an action for Drafts.

This group of actions is version 2 of the Track time actions.

Its purpose is to track time in a single draft made of successive timestamped entries.

It’s also to track actions that are noted inside the draft and shared from there to other apps. Drafts basically is ‘where text starts’. These actions make Drafts also ‘where action starts’.

You’ll find the 3 actions of version 1:

  • ‘Plus’ button (the new entry button) to create a new entry
  • ‘clock’ button to insert time
  • ‘down arrow’ button (the goto end button) to go straight to the end of draft

There are 3 other buttons:

  • ‘down arrow to bracket’ button (the action button) to add an action in the draft after the current line
  • ‘right arrow to bracket’ button (the edit button) to edit the current line with customized functions
  • ‘right arrow from bracket’ button (the share button) to share the current line to other apps through customized functions

All the buttons are in the keyboard Track time v2. They automatically update the timestamps and durations of the previous and current entry.

This version 2 of Track time here is a demo of what can be done.

In my version, I have customized the following functions and integrated them into Track time v2:

  1. Actions:
  • checkins in various places (bakery, supermarket, etc.)
  • commuting (by car, tramway, bus, metro, etc.)
  • eating (breakfast, lunch, dinner, etc.)
  • sleeping (go to bed, wake up)
  • project names (professional and personal one)
  • errand (walking, walking the dog, etc.)
  • routine (medics, various repetitive actions)
  • managing things (with only one verb I can complete then to detail the action: process, prepare, maintain, order, etc.)
  • focusing (same than managing, 1 verb, i.e.: work, write, discuss, study, tweak, etc.)
  • enjoying (1 verb: chat, rest, pause, read, watch, visit, etc.)
  1. Edits:
  • customize lines to prepare export to Day One app
  • numbered list
  • bullet list
  1. Shares:
  • reflecting on habits and quantified self (weight, snacks, feelings, meditation, etc.) and sharing to other apps such as Habitify, iOS Health app, etc.
  • hydration : reflect on drinks and sharing to WaterMinder app
  • share to other apps (iOS Reminder, iOS Calendar, Fantastical, Things, Agenda, iOS Camera, iOS share extensions, iOS Shortcuts, etc.)

And another action exports entries to Day One.

Sky is the limit!

Published in the Draft directory.

Track time

This is an action for Drafts.

I wrote these actions to track time in a single draft.

The draft is made of successive and chronological entries. The entries are separated by « *** ». The first line of each entry is a timestamp (yyyy-mm-dd-day HH:MM) and displays the duration ( => HH:MM) to the next entry. You can edit the separator and the timestamp format at the beginning of the Init script (with ‘gearing’ icon).

The first action (with a ‘plus’ icon) creates a new timestamped entry right after the one where the cursor is (the current entry).

The second action (with a ‘clock’ icon) updates the timestamp of the current entry. When the cursor is not on the timestamp line, this action also inserts the time (HH:MM) in the entry.

The third action (with a ‘down arrow’ icon) moves the cursor to the very end of the draft. It’s useful when, while reviewing past entries, you want to write down a new entry.

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.