The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Build a custom command launcher

To build a custom command launcher, you can create a lightweight desktop app that lets users type and execute commands quickly — similar to macOS Spotlight or tools like Alfred or Windows PowerToys Run. Below is a guide and sample code for building a custom command launcher in Python with Tkinter and custom logic for executing commands.


Features

  • Global hotkey to open launcher

  • Command input with autocomplete support

  • Execute shell commands or custom commands

  • Cross-platform (Windows, macOS, Linux)


🔧 Prerequisites

  • Python 3.x

  • keyboard, tkinter, subprocess, os libraries

    bash
    pip install keyboard

💻 Code: Custom Command Launcher (Python)

python
import os import subprocess import tkinter as tk from tkinter import StringVar, Entry, Listbox import keyboard import threading # Custom commands dictionary custom_commands = { "open chrome": "start chrome" if os.name == "nt" else "open -a 'Google Chrome'", "open vscode": "code", "shutdown": "shutdown /s /t 1" if os.name == "nt" else "shutdown now", } # Core launcher app class CommandLauncher: def __init__(self): self.root = tk.Tk() self.root.title("Command Launcher") self.root.geometry("400x100+600+300") self.root.overrideredirect(True) # No window decorations self.root.attributes('-topmost', True) self.var = StringVar() self.entry = Entry(self.root, textvariable=self.var, font=("Segoe UI", 14), width=40) self.entry.pack(padx=10, pady=20) self.entry.bind("<Return>", self.execute_command) self.entry.bind("<Escape>", lambda e: self.hide()) self.root.withdraw() # Hide on start def show(self): self.root.deiconify() self.entry.focus() self.var.set("") # Clear previous input def hide(self): self.root.withdraw() def execute_command(self, event=None): cmd = self.var.get().strip().lower() if cmd in custom_commands: cmd_to_run = custom_commands[cmd] else: cmd_to_run = cmd try: subprocess.Popen(cmd_to_run, shell=True) except Exception as e: print("Error:", e) self.hide() def run(self): self.root.mainloop() def hotkey_listener(launcher): keyboard.add_hotkey("ctrl+space", launcher.show) # Change shortcut here keyboard.wait() if __name__ == "__main__": launcher = CommandLauncher() threading.Thread(target=hotkey_listener, args=(launcher,), daemon=True).start() launcher.run()

🔍 How It Works

  • Press Ctrl + Space to open the launcher.

  • Type your command (e.g., open chrome, notepad, shutdown).

  • Press Enter to execute.

  • Press Escape to close the launcher without executing.


🧠 Expandability Ideas

  • Add autocomplete suggestions from a command history.

  • Save frequently used commands.

  • Allow script execution (e.g., Python or Bash).

  • Add plugin system for calculator, search, or URL launcher.

  • GUI styling with ttk or customtkinter.


📦 Packaging (Optional)

To make it a standalone app:

bash
pip install pyinstaller pyinstaller --noconsole --onefile launcher.py

Let me know if you want a version in another language (e.g., C#, JavaScript/Electron) or want to integrate it with AI command understanding.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About