Skip to content

Instantly share code, notes, and snippets.

@betafcc
Created May 8, 2021 14:05
Show Gist options
  • Save betafcc/3e0d5b0d99b7fae115cf371275ec8ca8 to your computer and use it in GitHub Desktop.
Save betafcc/3e0d5b0d99b7fae115cf371275ec8ca8 to your computer and use it in GitHub Desktop.
Opens a select in the touchbar
#!/usr/bin/env electron
const { app, BrowserWindow, TouchBar } = require("electron")
app.whenReady().then(() => {
const window = new BrowserWindow({
titleBarStyle: "hiddenInset",
width: 0,
height: 0,
})
window.loadURL("about:blank")
window.setTouchBar(
new TouchBar({
items: process.argv.slice(2).map(
label =>
new TouchBar.TouchBarButton({
label,
click: () => {
console.log(label)
app.exit(0)
},
})
),
})
)
})
@betafcc
Copy link
Author

betafcc commented May 8, 2021

Run

curl -s https://gist.githubusercontent.com/betafcc/3e0d5b0d99b7fae115cf371275ec8ca8/raw/928c3e180d2c7ef18b8dbabfa31d481f96287ac1/touchbar-select.js | npx electron '/dev/stdin' foo bar biz baz

Install

npm i -g electron
curl https://gist.githubusercontent.com/betafcc/3e0d5b0d99b7fae115cf371275ec8ca8/raw/928c3e180d2c7ef18b8dbabfa31d481f96287ac1/touchbar-select.js > /usr/local/bin/touchbar-select
chmod +x /usr/local/bin/touchbar-select

With applescript you can easily create a select dialog by running osascript -e 'choose from list {"foo","bar","biz","baz"}'.
Surprisingly, there is nothing nearly as easy if you want to show the dialog in touchbar instead.

With this electron script you just touchbar-select foo bar biz baz and that's it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment