Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from AppKit import NSApp
from vanilla import FloatingWindow, EditText, List, Button
from import getShortCuts
from lib.UI.fileBrowser import shortKeyToString
class CommandPalette:
def __init__(self):
shortcuts = getShortCuts()
self.shortcuts = {}
self.menuItems = {}
for key, item in shortcuts.items():
if item.keyEquivalent():
shortkey = item.keyEquivalentModifierMask(), item.keyEquivalent()
self.shortcuts[key] = shortkey
self.menuItems[key] = item
self.w = FloatingWindow((400, 280), 'CommandPalette',
minSize=(400, 200), maxSize=(400, 480))
x = y = p = 10
textHeight = 20
self.w.text = EditText((x, y, -p, textHeight), '',
placeholder='type to search...',
continuous=True, callback=self.updateListCallback)
y += textHeight + p
self.w.list = List(
(x, y, -p, -p),
[{"command": key, "keys": shortKeyToString(shortkey)} for key, shortkey in self.shortcuts.items()],
columnDescriptions=[{"title": "command"}, {"title": "keys", "width" : 100}],
allowsMultipleSelection=False, allowsEmptySelection=False,
def updateListCallback(self, sender):
search = sender.get()
foundItems = [{"command": key, "keys": shortKeyToString(shortkey)} for key, shortkey in self.shortcuts.items() if search in key]
def doubleClickCallback(self, sender):
items = self.w.list.get()
i = self.w.list.getSelection()[0]
command = items[i]['command']
menuItem = self.menuItems[command]
NSApp().sendAction_to_from_(menuItem.action(),, menuItem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment