Created
May 8, 2021 14:05
-
-
Save betafcc/3e0d5b0d99b7fae115cf371275ec8ca8 to your computer and use it in GitHub Desktop.
Opens a select in the touchbar
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
#!/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) | |
}, | |
}) | |
), | |
}) | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run
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.