rumps
repository·master·Indexed 25 days ago
https://github.com/jaredks/rumpsA Python library for creating Ridiculously Uncomplicated macOS status bar applications. It provides a simplified interface for building menu-based apps without requiring deep knowledge of PyObjC, offering features such as the rumps.App subclass, @rumps.clicked decorators, system notifications, alert dialogs, and TextFieldMenuItem for embedded text fields. It also supports bundling into standalone .app bundles using py2app.
What's inside rumps
- rumps is a library designed to create 'Ridiculously Uncomplicated Mac os x Python Statusbar apps'. It exposes Objective-C classes as Python classes and functions, simplifying the creation of macOS status bar applications. It is intended as a lightweight alternative to heavy GUI frameworks like PyQt or Tkinter when you only need a simple interface for end-user interaction (such as configuration options or execution switches) in the macOS menu bar.
Create standalone macOS applications with py2app
masterTo bundle a
rumpsapplication into a standalone.appbundle, use thepy2applibrary.When configuring your
setup.py, you must include'rumps'in thepackageslist within thepy2appoptions.For status bar-based applications that should run in the background (without a Dock icon or the ability to be tabbed to in the App Switcher), set
'LSUIElement': Truein theplistsection of your options.from setuptools import setup APP = ['example_class.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': True, 'plist': { 'LSUIElement': True, }, 'packages': ['rumps'], } setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], )Configure Python virtual environments for rumps
masterIt is not recommended to use
virtualenvwithrumpsdue to issues with how the Python executable is copied. Instead, use the standardvenvmodule (included with Python 3) to ensure proper functionality.python3 -m venv envEnable debugging mode in rumps
masterTo view informational messages and debug your application, enable
debug_modeby callingrumps.debug_mode(True)in your code.import rumps rumps.debug_mode(True)Package rumps as a standalone app with py2app
masterTo create a standalone macOS application, use
py2app. Ensurerumpsis included in thepackageslist in yourOPTIONS. For background apps (no Dock icon), set'LSUIElement': Truein theplistconfiguration.Example
setup.py:from setuptools import setup APP = ['example_class.py'] DATA_FILES = [] OPTIONS = { 'argv_emulation': True, 'plist': { 'LSUIElement': True, }, 'packages': ['rumps'], } setup( app=APP, data_files=DATA_FILES, options={'py2app': OPTIONS}, setup_requires=['py2app'], )Then run the following command to build the app:
python setup.py py2appBuild a standalone application bundle
masterOnce you have configured your
setup.pywith the necessaryrumpspackage requirements andpy2appoptions, run the following command to build the standalone.appbundle:python setup.py py2appInstall rumps via pip
masterInstall the
rumpspackage usingpip. Note that you may needsudoif installing to a system-wide location.pip install rumpsInstall rumps from source
masterInstall the
rumpspackage directly from the source code usingsetup.py. Note that you may needsudoif installing to a system-wide location.python setup.py installCustomize or remove the quit button in rumps.App
masterWhen initializing a
rumps.App, you can use thequit_buttonparameter to customize the text of the quit button or remove it entirely by passingNone.Warning: If you set
quit_button=None, you must provide an alternative way to exit the application (e.g., a menu item that callsrumps.quit_application()), otherwise you will have to force quit the process.# Removing the default quit button app = rumps.App('Hallo Thar', menu=['Print Something', 'On/Off Test', 'Clean Quit'], quit_button=None) # Providing an alternative exit method @rumps.clicked('Clean Quit') def clean_up_before_quit(_): rumps.quit_application() app.run()View debug messages for py2app bundles
masterWhen testing a
.appbundle generated viapy2app, using the standardopen {your app name}.appcommand will hide debug messages. To see the output, you must run the executable directly from the terminal.If your app is in the default
distfolder, run the executable using the following path structure:./dist/{your app name}.app/Contents/MacOS/{your app name}Create a macOS status bar app with rumps
masterTo create a macOS status bar application, subclass
rumps.Appand use decorators like@rumps.clicked(name)to define callback functions for menu items. You can trigger system alerts usingrumps.alert()and notifications usingrumps.notification(). To start the application, call the.run()method on your class instance.import rumps class AwesomeStatusBarApp(rumps.App): @rumps.clicked("Preferences") def prefs(self, _): rumps.alert("jk! no preferences available!") @rumps.clicked("Silly button") def onoff(self, sender): sender.state = not sender.state @rumps.clicked("Say hi") def sayhi(self, _): rumps.notification("Awesome title", "amazing subtitle", "hi!!1") if __name__ == "__main__": AwesomeStatusBarApp("Awesome App").run()Create a basic application using a subclass of rumps.App
masterTo build a standard
rumpsapplication, subclassrumps.Appand implement your logic within methods. You can define the menu items in the__init__method and use the@rumps.clickeddecorator to register callback functions for specific menu items.import rumps class AwesomeStatusBarApp(rumps.App): def __init__(self): super(AwesomeStatusBarApp, self).__init__("Awesome App") self.menu = ["Preferences", "Silly button", "Say hi"] @rumps.clicked("Preferences") def prefs(self, _): rumps.alert("jk! no preferences available!") @rumps.clicked("Silly button") def onoff(self, sender): sender.state = not sender.state @rumps.clicked("Say hi") def sayhi(self, _): rumps.notification("Awesome title", "amazing subtitle", "hi!!1") if __name__ == "__main__": AwesomeStatusBarApp().run()