Skip to content

eatgrass/obsidian-pomodoro-timer

Repository files navigation

Pomodoro Timer for Obsidian

image

Introduction

This plugin integrates a customizable Pomodoro timer into your Obsidian workspace, helping you focus and manage your time effectively.

Features

  • Customizable Timer: Set your work and break intervals to suit your productivity style.
  • Audible Alerts: Stay on track with audio notifications signaling the end of each session.
  • Status Bar Display: Monitor your progress directly from Obsidian's status bar to keep focusing.
  • Daily Note Integration: Automatically log your sessions in your daily notes for better tracking.
  • Task Tracking: Automatically refresh the 'actual time' field for the task in focus.

Notification

Custom Notification Sound

  1. Put the audio file into your vault.
  2. Set its path ralative to the vault's root. For example: your audio file is in AudioFiles and named notification.mp3, your path would be AudioFiles/notification.mp3. Don't forget the file extension (like .mp3, .wav etc.).
  3. Click the play button next to the path to verify the audio

Task Tracking

To activate this feature, first enable it in the settings. Then add pomodoros inline-field after your task's text description as below. The pomodoro timer will then automatically update the actual count at the end of each work session.

Important: Ensure to add this inline-field before the Tasks plugin's fields. Placing it elsewhere may result in incorrect rendering within the Tasks Plugin.

-   [ ] Task with specified expected and actual pomodoros fields [πŸ…:: 3/10]
-   [ ] Task with only the actual pomodoros field [πŸ…:: 5]
-   [ ] With Task plugin enabled [πŸ…:: 5] βž• 2023-12-29 πŸ“… 2024-01-10

Log

Log Format

The standard log formats are as follows For those requiring more detailed logging, consider setting up a custom [log template](#Custom Log Template) as described below.

Simple

**WORK(25m)**: 20:16 - 20:17
**BREAK(25m)**: 20:16 - 20:17

Verbose

- πŸ… (pomodoro::WORK) (duration:: 25m) (begin:: 2023-12-20 15:57) - (end:: 2023-12-20 15:58)
- πŸ₯€ (pomodoro::BREAK) (duration:: 25m) (begin:: 2023-12-20 16:06) - (end:: 2023-12-20 16:07)

Custom Log Template (Optional)

  1. Install the Templater plugin.
  2. Compose your log template script using the log object, which stores session information.
// TimerLog
{
    duration: number,  // duratin in minutes
    session: number,   // session length
    finished: boolean, // if the session is finished?
    mode: string,      // 'WORK' or 'BREAK'
    begin: Moment,     // start time
    end: Moment,       // end time
    task: TaskItem,    // focused task
}

// TaskItem
{
    path: string,         // task file path
    fileName: string,     // task file name
    text: string,         // the full text of the task
    name: string,         // editable task name (default: task description)
    status: string,       // task checkbox symbol
    blockLink: string,    // block link id of the task
    checked: boolean,     // if the task's checkbox checked
    done: string,         // done date
    due: string,          // due date
    created: string,      // created date
    cancelled: string,    // cancelled date
    scheduled: string,    // scheduled date
    start: string,        // start date
    description: string,  // task description
    priority: string,     // task priority
    recurrence: string,   // task recurrence rule
    tags: string[],       // task tags
	expected: number,     // expected pomodoros
	actual: number        // actual pomodoros
}

here is an example

<%*
if (log.mode == "WORK") {
  if (!log.finished) {
    tR = `🟑 Focused ${log.task.name} ${log.duration} / ${log.session} minutes`;
  } else {
    tR = `πŸ… Focused ${log.task.name} ${log.duration} minutes`;
  }
} else {
  tR = `β˜•οΈ Took a break from ${log.begin.format("HH:mm")} to ${log.end.format(
    "HH:mm"
  )}`;
}
%>

Examples of Using with DataView

Log Table

This DataView script generates a table showing Pomodoro sessions with their durations, start, and end times.

image

```dataviewjs
const pages = dv.pages()
const table = dv.markdownTable(['Pomodoro','Duration', 'Begin', 'End'],
pages.file.lists
.filter(item=>item.pomodoro)
.sort(item => item.end, 'desc')
.map(item=> {

    return [item.pomodoro, `${item.duration.as('minutes')} m`, item.begin, item.end]
})
)
dv.paragraph(table)

```  

Summary View

This DataView script presents a summary of Pomodoro sessions, categorized by date.

image

```dataviewjs
const pages = dv.pages();
const emoji = "πŸ…";
dv.table(
  ["Date", "Pomodoros", "Total"],
  pages.file.lists
    .filter((item) => item?.pomodoro == "WORK")
    .groupBy((item) => {
      if (item.end && item.end.length >= 10) {
        return item.end.substring(0, 10);
      } else {
        return "Unknown Date";
      }
    })
    .map((group) => {
      let sum = 0;
      group.rows.forEach((row) => (sum += row.duration.as("minutes")));
      return [
        group.key,
        group.rows.length > 5
          ? `${emoji}  ${group.rows.length}`
          : `${emoji.repeat(group.rows.length)}`,
        `${sum} min`,
      ];
    })
)
```

CSS Variables

Variable Default
--pomodoro-timer-color var(--text-faint)
--pomodoro-timer-elapsed-color var(--color-green)
--pomodoro-timer-text-color var(--text-normal)
--pomodoro-timer-dot-color var(--color-ted)

FAQ

  1. How to Switch the Session

To switch sessions, simply click on the Work/Break label displayed on the timer.

  1. How to completely disable Break sessions

You can adjust the break interval setting to 0, this will turn off Break sessions.


BuyMeACoffee