|
| 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 | +} |
0 commit comments