-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
list_timers.js
executable file
·50 lines (43 loc) · 1.14 KB
/
list_timers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
ObjC.import('stdlib');
const timers = JSON.parse($.getenv('timers_list'));
const calculateFireTime = (seconds) => {
const options = {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
};
return new Intl.DateTimeFormat('en-US', options).format(seconds);
};
const items = Object.keys(timers)
.sort((timerA, timerB) => Number(timerA) - Number(timerB))
.map((id) => {
const message = timers[id].message;
const isPomodoro = timers[id].isPomodoro;
return {
title: calculateFireTime(id),
subtitle: message,
arg: id,
icon: {
path: isPomodoro ? './list_pomodoro.png' : './list_timer.png',
},
variables: {
'selected_timer_id': id,
'timer_message': message,
'timer_is_pomodoro': isPomodoro,
},
};
});
items.push({
title: items.length === 0 ? 'No active timers. Create new one?' : 'Create new',
arg: 'new',
icon: {
path: './add.png',
},
});
return JSON.stringify({
items,
});
}