Skip to content

Instantly share code, notes, and snippets.

@NickHatBoecker
Last active November 24, 2022 11:29
Show Gist options
  • Save NickHatBoecker/a089c858217803491a3fefe914062854 to your computer and use it in GitHub Desktop.
Save NickHatBoecker/a089c858217803491a3fefe914062854 to your computer and use it in GitHub Desktop.
DND Toggle:: Node Helper
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