Last active
November 24, 2022 11:29
-
-
Save NickHatBoecker/a089c858217803491a3fefe914062854 to your computer and use it in GitHub Desktop.
DND Toggle:: Node Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const port = 5511 | |
app.get('/get-dnd-state', (req, res) => { | |
const { exec } = require('child_process') | |
exec('osascript -l JavaScript ~/bin/get-focus-mode.scpt', (error, stdout, stderr) => { | |
if (error || stderr) { | |
res.send('No focus') | |
return | |
} | |
res.send(stdout) | |
}) | |
}) | |
app.get('/toggle-dnd-state', (req, res) => { | |
const { execSync } = require('child_process') | |
const activateDnd = req.query.activateDnd === 'true' | |
let shortcut = 'DND Off' | |
if (activateDnd) { | |
shortcut = 'DND On' | |
} | |
execSync(`shortcuts run "${shortcut}"`, (error, stdout, stderr) => { | |
// Do nothing here for now (you could catch the error or something) | |
}) | |
res.send(activateDnd ? 'DND was turned on' : 'DND was turned off') | |
}) | |
app.listen(port, () => { | |
console.log(`App listening on port ${port}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment