Skip to content

Commit d073b2d

Browse files
landendanylukdehesa
authored andcommitted
add Timing commands for starting/stopping timers
1 parent ba84bea commit d073b2d

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
5.28 KB
Loading
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/osascript -l JavaScript
2+
3+
// Note: Timing.app is required with an Expert or Connect subscription
4+
// Learn more and install: https://timingapp.com
5+
6+
// Required parameters:
7+
// @raycast.schemaVersion 1
8+
// @raycast.title Start Timer
9+
// @raycast.mode silent
10+
11+
// Optional parameters:
12+
// @raycast.icon images/timing-logo.png
13+
// @raycast.argument1 { "type": "text", "placeholder": "Project", "optional": true }
14+
// @raycast.argument2 { "type": "text", "placeholder": "Title", "optional": true }
15+
// @raycast.argument3 { "type": "text", "placeholder": "Duration", "optional": true }
16+
// @raycast.packageName Timing
17+
18+
// Documentation:
19+
// @raycast.description Start a timer
20+
// @raycast.author Landen Danyluk
21+
// @raycast.authorURL https://github.com/landendanyluk
22+
23+
function run(argv) {
24+
const timing = Application('TimingHelper');
25+
26+
// throw if AppleScript support is not enabled
27+
if (!timing.scriptingSupportAvailable()) {
28+
console.log('Scripting support requires an Expert or Connect subscription');
29+
throw new Error();
30+
}
31+
32+
// throw if both project and title are empty
33+
if (!(argv[0] || argv[1])) {
34+
console.log("Please enter a project name or title");
35+
throw new Error();
36+
}
37+
38+
let project;
39+
if (argv[0] !== "") {
40+
// check if project exists
41+
const projects = timing.projects.whose({ name: argv[0] });
42+
if (!projects.length) {
43+
console.log("Project does not exist");
44+
throw new Error();
45+
} else {
46+
// if there's more than one project with the same name, choose the first one in the list
47+
project = projects[0];
48+
}
49+
}
50+
const withTitle = argv[1];
51+
const forAbout = Number(argv[2]) * 60;
52+
if (isNaN(forAbout)) {
53+
console.log("Please enter a valid duration");
54+
throw new Error();
55+
}
56+
57+
// JXA will complain if a key is present but undefined, so we have to add them like this
58+
const options = {};
59+
if (project) {
60+
options.project = project;
61+
}
62+
if (withTitle) {
63+
options.withTitle = withTitle;
64+
}
65+
if (forAbout) {
66+
options.forAbout = forAbout;
67+
}
68+
69+
timing.startTimer(options);
70+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/osascript -l JavaScript
2+
3+
// Note: Timing.app is required with an Expert or Connect subscription
4+
// Learn more and install: https://timingapp.com
5+
6+
// Required parameters:
7+
// @raycast.schemaVersion 1
8+
// @raycast.title Stop Timer
9+
// @raycast.mode silent
10+
11+
// Optional parameters:
12+
// @raycast.icon images/timing-logo.png
13+
// @raycast.packageName Timing
14+
15+
// Documentation:
16+
// @raycast.description Stop the active timer
17+
// @raycast.author Landen Danyluk
18+
// @raycast.authorURL https://github.com/landendanyluk
19+
20+
function run() {
21+
const timing = Application('TimingHelper');
22+
23+
// throw if AppleScript support is not enabled
24+
if (!timing.scriptingSupportAvailable()) {
25+
console.log('Scripting support requires an Expert or Connect subscription');
26+
throw new Error();
27+
}
28+
29+
timing.stopCurrentTimer({ notification: true });
30+
}

0 commit comments

Comments
 (0)