### Check Configuration File Existence in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Shows how to check if a SwiftBar plugin's configuration file already exists on the system. This is useful for determining if initial setup or loading is required. ```python >>> from swiftbarmenu import Configuration >>> c = Configuration() >>> c.exists() False >>> c.persist() >>> c.exists() True ``` -------------------------------- ### Install swiftbarmenu Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Installs the swiftbarmenu Python package using pip. This is the primary method for setting up the library for use in your SwiftBar or xbar plugins. ```console pip install swiftbarmenu ``` -------------------------------- ### Clear All or Nested Items in SwiftBar Menu in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Provides examples for clearing all items from a SwiftBar menu or clearing nested items within a specific menu item. This is useful for resetting menu state. ```python >>> from swiftbarmenu import Menu >>> m = Menu('My menu') >>> m.add_header('Header 2') Header 2 >>> m.add_header('Header 3') Header 3 >>> m.add_item('Item 1') Item 1 >>> m.add_item('Item 2') Item 2 >>> m.clear() >>> m >>> m.header [] >>> m.body [] ``` ```python >>> from swiftbarmenu import Menu >>> m = Menu('My menu') >>> item1 = m.add_item('Item 1') >>> item1.add_item('Item 1.1') Item 1.1 >>> item1.add_item('Item 1.2') Item 1.2 >>> item1.add_item('Item 1.3') Item 1.3 >>> item1.clear() >>> m My menu --- Item 1 ``` -------------------------------- ### Basic Configuration Management in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to initialize a Configuration object, set key-value pairs with optional types (int, bool), persist them to a file, and retrieve them. This is fundamental for managing plugin settings. ```python >>> from swiftbarmenu import Configuration >>> c = Configuration() >>> c.set("api_key", "12345") >>> c.set("refresh_interval", 60, type="int") >>> c.set("notifications_enabled", True, type="bool") >>> c.persist() >>> api_key = c.get("api_key") >>> interval = c.get("refresh_interval", type="int") >>> notifications = c.get("notifications_enabled", type="bool") >>> api_key '12345' >>> interval 60 >>> notifications True ``` -------------------------------- ### Loading Existing Configuration in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Illustrates how to load configuration settings from an existing file. It highlights disabling auto-loading and manually calling the load method, which silently continues if the file is not found. ```python >>> from swiftbarmenu import Configuration >>> c = Configuration(auto_load=False) # Disable configuration auto-loading >>> c.load() # Loads configuration from file if it exists >>> # Configuration is now ready to use >>> api_key = c.get("api_key") >>> api_key '12345' # Value loaded from file ``` -------------------------------- ### Organizing Configuration with Sections in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to group related configuration settings into logical sections using the `section()` method. This improves organization for complex configurations. ```python >>> from swiftbarmenu import Configuration >>> c = Configuration() >>> api_section = c.section("API") >>> api_section.set("key", "12345") >>> api_section.set("endpoint", "https://api.example.com") >>> ui_section = c.section("UI") >>> ui_section.set("theme", "dark") >>> ui_section.set("font_size", 14, type="int") >>> c.persist() >>> api_section.get("key") '12345' >>> ui_section.get("font_size", type="int") 14 ``` -------------------------------- ### Create a basic menu with swiftbarmenu Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates the fundamental usage of the `Menu` class from the swiftbarmenu library. It shows how to initialize a menu, add simple text items, and then dump the menu structure to be rendered by SwiftBar. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_item('Item 1') m.add_item('Item 2', sep=True, checked=True) item2 = m.add_item('Item 2', sep=True, checked=True) item2.add_item('Subitem 1') item2.add_item('Subitem 2') m.add_link('Item 3', 'https://example.com', color='yellow') m.add_item(':thermometer: Item 4', color='orange', sfcolor='black', sfsize=20) m.dump() ``` -------------------------------- ### Basic menu creation and output Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Illustrates the basic creation of a SwiftBar menu using the `swiftbarmenu` library. It shows adding items and then printing the menu's output, which is formatted for SwiftBar. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_item('Item 1') m.add_item('Item 2') m.dump() ``` -------------------------------- ### Opening Configuration File Editor in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Shows how to open the plugin's configuration file directly in the system's default text editor or a specified editor. This facilitates manual editing of settings. ```python >>> from swiftbarmenu import Configuration >>> c = Configuration() >>> c.open_editor() # Opens in TextEdit by default >>> c.open_editor("Visual Studio Code") # Opens in VS Code ``` -------------------------------- ### Configuration: Manage Plugin Settings with INI Files (Python) Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Illustrates the use of the Configuration class for managing plugin settings via INI files. It supports typed value retrieval, sections for organization, and persistence. ```python from swiftbarmenu import Configuration # Initialize configuration (auto-loads existing config) c = Configuration() # Set configuration values (stored as strings internally) c.set("api_key", "sk-123456789") c.set("refresh_interval", 60) c.set("debug_mode", True) # Save configuration to file c.persist() # Get values with type conversion api_key = c.get("api_key") # Returns string interval = c.get("refresh_interval", type="int") # Returns int: 60 debug = c.get("debug_mode", type="bool") # Returns bool: True # Get with default values for missing keys timeout = c.get("timeout", default=30, type="int") # Returns 30 # Check if configuration file exists if c.exists(): print("Configuration loaded from file") # Use sections to organize settings api_section = c.section("API") api_section.set("endpoint", "https://api.example.com") api_section.set("timeout", 30) api_section.set("retries", 3) ui_section = c.section("UI") ui_section.set("theme", "dark") ui_section.set("font_size", 14) ui_section.set("show_icons", True) c.persist() # Read from sections endpoint = api_section.get("endpoint") # 'https://api.example.com' retries = api_section.get("retries", type="int") # 3 font_size = ui_section.get("font_size", type="int") # 14 show_icons = ui_section.get("show_icons", type="bool") # True # Open config file in editor for manual editing c.open_editor() # Opens in TextEdit c.open_editor("Visual Studio Code") # Opens in VS Code # Disable auto-loading for fresh start fresh_config = Configuration(auto_load=False) fresh_config.load() # Manually load when ready # Configuration file format (config.ini): # [DEFAULT] # api_key = sk-123456789 # refresh_interval = 60 # debug_mode = True # # [API] # endpoint = https://api.example.com # timeout = 30 # retries = 3 # # [UI] # theme = dark # font_size = 14 # show_icons = True ``` -------------------------------- ### Create and Show Basic Notifications in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates the basic usage of the `Notification` class in SwiftBar to create and display notifications. It shows how to set title, subtitle, body, and an optional href. ```python >>> from swiftbarmenu import Notification >>> n = Notification("Title", "Subtitle", "Body", "https://example.com") >>> n.show() Notification(title='Title', subtitle='Subtitle', body='Body', href='https://example.com') >>> n Notification(title='Title', subtitle='Subtitle', body='Body', href='https://example.com') ``` -------------------------------- ### Providing Default Values for Configuration in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Explains how to specify a default value when retrieving a configuration setting that might not exist. This prevents errors and simplifies handling missing configurations. ```python >>> from swiftbarmenu import Configuration >>> c = Configuration() >>> value = c.get("nonexistent_key", default="default_value") >>> value 'default_value' ``` -------------------------------- ### Cloning Repository using Git Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Provides the command to clone the swiftbarmenu project repository from GitHub. This is the first step for setting up the development environment locally. ```sh git clone git@github.com:sdelquin/swiftbarmenu.git cd swiftbarmenu ``` -------------------------------- ### Create and Display Menus with Menu Class Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Demonstrates how to use the `Menu` class to create and structure menu bar content. It covers adding header items, body items with parameters, and separators. The `dump()` method is used to output the formatted menu to standard output for SwiftBar rendering. ```python from swiftbarmenu import Menu # Create a menu with a header title m = Menu('Weather App') # Add multiple header items (shown cycling in menu bar) m.add_header('72°F') m.add_header('Sunny') # Add body items with various parameters m.add_item('Current Conditions', color='blue', size=14) m.add_item('Temperature: 72°F') m.add_item('Humidity: 45%') # Add a separator before settings section m.add_item('Settings...', sep=True, color='gray') # Output the menu for SwiftBar m.dump() # Output: # Weather App # 72°F # Sunny # --- # Current Conditions|color=blue size=14 # Temperature: 72°F # Humidity: 45% # --- # Settings...|color=gray ``` -------------------------------- ### Save and Load Plugin Data with Persistence in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Illustrates the basic usage of the `Persistence` class in SwiftBar to save and load plugin data. It shows how to store dictionaries and clear the stored data. ```python >>> from swiftbarmenu import Persistence >>> sample_data = { "data": "test", "nested": { "data1": "test", "data2": "test" } } >>> p = Persistence() >>> p.save(sample_data) >>> stored_data = p.load() >>> stored_data {'data': 'test', 'nested': {'data1': 'test', 'data2': 'test'}} >>> p.clear() >>> stored_data = p.load() >>> stored_data {} ``` -------------------------------- ### Save and Load Plugin Data with Custom Filename in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to use the `Persistence` class with a custom filename to save and load SwiftBar plugin data. This allows for managing multiple data stores. ```python >>> from swiftbarmenu import Persistence >>> sample_data = { "data": "test", "nested": { "data1": "test", "data2": "test" } } >>> p = Persistence("example") >>> p.save(sample_data) >>> stored_data = p.load() >>> stored_data {'data': 'test', 'nested': {'data1': 'test', 'data2': 'test'}} >>> p.clear() >>> stored_data = p.load() >>> stored_data {} ``` -------------------------------- ### Persistence: Save and Load Data with Custom File Names (Python) Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Demonstrates how to use the Persistence class to save and load data to separate files. Each instance manages its own file, allowing for distinct data stores. ```python from swiftbarmenu import Persistence # Use custom file name for separate data stores cache = Persistence("cache") cache.save({"items": ["a", "b", "c"]}) history = Persistence("history") history.save({"events": ["login", "refresh", "logout"]}) # Each persistence instance manages its own file print(cache.load()) # {"items": ["a", "b", "c"]} print(history.load()) # {"events": ["login", "refresh", "logout"]} # File path info # print(p) # Persistence(file_name='data', path='/path/to/plugin/data.pkl') ``` -------------------------------- ### Opening Project Folder in VS Code Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Command to open the cloned swiftbarmenu project directory in Visual Studio Code. This action can trigger the Dev Containers extension. ```sh code . ``` -------------------------------- ### Add styled menu items Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates adding menu items with various parameters like color, size, and checked state. It shows how these parameters are appended to the item's string representation. ```python from swiftbarmenu import Menu m = Menu('My menu') item = m.add_item('Item 1', color='orange', size=18, checked=True) print(item) m.dump() print(item.text) print(item.params) ``` -------------------------------- ### Execute Scripts on Click with add_action Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Explains the `add_action()` method, which creates menu items designed to execute scripts upon being clicked. By default, it runs the current plugin script with specified arguments, but the `bash` parameter allows for the execution of alternative scripts. ```python from swiftbarmenu import Menu m = Menu('Actions Demo') ``` -------------------------------- ### Add Menu Items with Parameters and Nesting using MenuItem Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Illustrates the use of the `MenuItem` class to create individual menu entries with various SwiftBar parameters like `checked`, `color`, `size`, and `font`. It also shows how to create nested submenus by chaining `add_item()` calls and accessing item properties. ```python from swiftbarmenu import Menu, MenuItem m = Menu('Tasks') # Add items with various SwiftBar parameters m.add_item('Completed Task', checked=True, color='green') m.add_item('Pending Task', checked=False, color='orange') m.add_item('Important!', color='red', size=16, font='Helvetica-Bold') # Access returned MenuItem to add nested items projects = m.add_item('Projects') projects.add_item('Website Redesign') projects.add_item('Mobile App') backend = projects.add_item('Backend API') backend.add_item('Authentication') backend.add_item('Database Schema') # Access item properties item = m.add_item('Sample', color='blue', size=12) print(item.text) # 'Sample' print(item.params) # {'color': 'blue', 'size': 12} m.dump() # Output: # Tasks # --- # Completed Task|checked=True color=green # Pending Task|checked=False color=orange # Important!|color=red size=16 font=Helvetica-Bold # Projects # -- Website Redesign # -- Mobile App # -- Backend API # ---- Authentication # ---- Database Schema # Sample|color=blue size=12 ``` -------------------------------- ### Use SF Symbols in SwiftBar Menus Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Illustrates how to incorporate Apple's SF Symbols into SwiftBar menu items and links. It shows how to use the ':symbol_name:' syntax for icons and customize their appearance using 'sfcolor' and 'sfsize' parameters, independent of text styling. ```python from swiftbarmenu import Menu m = Menu(':cloud.sun: Weather') # Add items with SF Symbols m.add_item(':sun.max: Sunny', sfcolor='yellow') m.add_item(':cloud.rain: Rainy', sfcolor='blue', sfsize=18) m.add_item(':thermometer: Temperature: 72°F', color='orange', sfcolor='red') m.add_item(':wind: Wind: 5 mph') # Combine icons with links m.add_link(':globe: Weather Website', 'https://weather.com', sfcolor='green') m.dump() ``` -------------------------------- ### Add SF Symbols to menu items Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to include Apple's SF Symbols directly in menu item text using the `:symbol_name:` syntax. It also shows how to apply colors specifically to these symbols. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_item('Sunny! :sun.max:') m.add_item('Cloudy! :cloud.rain:', sfcolor='blue') m.dump() ``` -------------------------------- ### Add Nested Actions to Menu Items in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to add nested actions to menu items using the swiftbarmenu library. This allows for more complex interactions within a menu structure. ```python >>> from swiftbarmenu import Menu >>> m = Menu('My menu') >>> item1 = m.add_item('Item 1') >>> item1.add_action("Test action...", ["test"]) >>> m.dump() My menu --- Item 1 -- Test action...|bash=/usr/local/swiftbar_plugins/test_plugin.1h.py param0=test refresh=false terminal=false ``` -------------------------------- ### Add Actions to SwiftBar Menu Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Demonstrates how to add various types of actions to a SwiftBar menu. This includes simple actions with parameters, actions that execute custom bash scripts, and nested actions within submenus. It also shows how to add built-in refresh actions with custom text and separators. ```python from swiftbarmenu import Menu m = Menu() # Add action that re-runs current plugin with parameters m.add_action('Refresh Data', ['refresh']) m.add_action('Set Mode', ['mode', 'dark']) # Add action with custom script m.add_action('Say Hello', bash='/usr/bin/say', action_params=['Hello World']) m.add_action('Open Folder', bash='/usr/bin/open', action_params=['/tmp']) # Nested action inside a submenu settings = m.add_item('Settings') settings.add_action('Reset to Defaults', ['reset', 'all']) settings.add_action('Clear Cache', ['clear', 'cache']) # Add built-in refresh action m.add_action_refresh() # Adds "Refresh..." item m.add_action_refresh('Reload Now', sep=True) # Custom text with separator m.dump() ``` -------------------------------- ### Persist Plugin Data with SwiftBar Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Explains the use of the `Persistence` class to save and load dictionary data between SwiftBar plugin executions. It utilizes Python's pickle module and stores data in SwiftBar's designated plugin data directory, demonstrating save, load, and clear operations. ```python from swiftbarmenu import Persistence # Initialize persistence (default file: data.pkl) p = Persistence() # Save data user_data = { "last_refresh": "2024-01-15T10:30:00", "api_calls": 42, "settings": { "theme": "dark", "refresh_interval": 300 } } p.save(user_data) # Load data (returns empty dict if file doesn't exist) loaded = p.load() print(loaded["api_calls"]) # 42 print(loaded["settings"]["theme"]) # 'dark' # Clear stored data p.clear() print(p.load()) # {} ``` -------------------------------- ### Add Clickable URLs with add_link Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Shows how to use the `add_link()` method to create menu items that open URLs when clicked. This method is a convenient wrapper for `add_item()` using the `href` parameter, allowing for easy integration of web links into the menu. ```python from swiftbarmenu import Menu m = Menu('Quick Links') # Add clickable links m.add_link('GitHub', 'https://github.com') m.add_link('Documentation', 'https://docs.example.com', color='blue') m.add_link('Support', 'mailto:support@example.com', color='green') # Equivalent to using add_item with href parameter m.add_item('SwiftBar', href='https://swiftbar.app', color='orange') m.dump() # Output: # Quick Links # --- # GitHub|href=https://github.com # Documentation|href=https://docs.example.com color=blue # Support|href=mailto:support@example.com color=green # SwiftBar|href=https://swiftbar.app color=orange ``` -------------------------------- ### Add Action Item to Menu (Python) Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Shows how to add an action item to a SwiftBar menu that executes a script when clicked. By default, it executes the current plugin script with provided parameters. The `bash` parameter can specify a custom script. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_action("Test action...", ["test"]) ``` ```python m.add_action("Echo action...", bash="/bin/echo", action_params=["test"]) ``` -------------------------------- ### Verify MenuItem instance Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Confirms that items added to a `Menu` object are indeed instances of the `MenuItem` class. It also demonstrates how to access the text attribute of a `MenuItem`. ```python from swiftbarmenu import MenuItem m = Menu('My menu') item = m.add_item('Item 1') print(isinstance(item, MenuItem)) print(item.text) ``` -------------------------------- ### Access and Manipulate Menu Headers and Body in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Illustrates how to access and manipulate the header and body elements of a SwiftBar menu. This includes adding headers and items, and accessing them programmatically. ```python >>> from swiftbarmenu import Menu >>> m = Menu('My menu') >>> m.add_header('Header 2') Header 2 >>> m.add_header('Header 3') Header 3 >>> m.add_item('Item 1') Item 1 >>> m.add_item('Item 2') Item 2 >>> m.header [My menu, Header 2, Header 3] >>> m.body [Item 1, Item 2] ``` -------------------------------- ### Add multiple headers to a menu Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Shows how to add multiple header items to a SwiftBar menu using the `add_header` method. Headers help organize menu sections. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_header('Header 2') m.add_header('Header 3') m.dump() ``` -------------------------------- ### Create nested menu items Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Shows how to create hierarchical menus by adding sub-items to an existing menu item. This allows for complex menu structures within SwiftBar. ```python from swiftbarmenu import Menu m = Menu('My menu') item1 = m.add_item('Item 1') item1.add_item('Item 1.1') item1.add_item('Item 1.2') item1.add_item('Item 1.3') m.dump() ``` -------------------------------- ### Add a link to a menu item Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Illustrates how to add a clickable link as a menu item using the `add_link` method. This is a shortcut for adding an item with an `href` parameter. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_link('GitHub', 'https://github.com') m.dump() ``` -------------------------------- ### Add Image to Menu Item (Python) Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to add an image to a menu item using its file path. This is a shortcut for adding an item with an 'image' parameter. Recommended image size is 16x16 pixels. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_image('tests/images/parrot.png', 'Parrot') ``` ```python m.add_item('Parrot', image='iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAJZlWElmTU0AKgAAAAgABQEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAAExAAIAAAARAAAAWodpAAQAAAABAAAAbAAAAAAAAABgAAAAAQAAAGAAAAABd3d3Lmlua3NjYXBlLm9yZwAAAAOgAQADAAAAAQABAACgAgAEAAAAAQAAABCgAwAEAAAAAQAAABAAAAAA4+VmVAAAAAlwSFlzAAAOxAAADsQBlSsOGwAAAWRpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDYuMC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIj4KICAgICAgICAgPHhtcDpDcmVhdG9yVG9vbD53d3cuaW5rc2NhcGUub3JnPC94bXA6Q3JlYXRvclRvb2w+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgqyyWIhAAACL0lEQVQ4Eb1TXUiTURh+ztn2bW7OmGa2DAIpt8ogRxS0q6Ifbyy88MIuEoIgUOznIop+WAWSlGHSTdBVN10s6C6Tlo0i+5EULFhQ68fSOecmubl92/fz9m06ZrHVXS8cznue93le3vc95wD/NpaApeYLYCpGZcXAPDazfXdr+ZrVJ3UNTofu2/eg7uvEQfZ8MJSPZ3f98kPBJ5bY2txltgp9ZC3Hu+YmsESiUuDsEHYN9hZ4RRLceIJagQynfcFVHY2j62EbTyFwqdvLjx2pd9bVTS0XZ/3fWuh/hQpZxFOjGa6EAqyYMqHlphsVcb7nx8O74xvs9sifCXge8BC4kkG/YIIrk9RKk7WV0iOjUjAZ148UE2e1uRl0+1AlPMJ1ZkR7fB6ILVQjGnbguJ/9XDvHO9inAQ0tbrkWLpzYcipkcvQOiW5EpVpY5JXomnyG+tTwyxc23T0DIQ2oUUllYUlSwjqJR8fS6Xm/3y8zELF9h/uuTNt3nuPVNWiqHEHDzOjbhfH3iZjZ6OYK6VUVcwCZGGNlinZQFDVGoJAsqUdzFfQccFsjnXcet22c2OGKDMSASSdzeSO3O9uc2hAkbZyzekG2iKroIKK9pNJ+znhjWlZalm6B+Pmx0OuLVfe3GeLJs2zzmavFO15EPR4Pt00HNqVFdXYRaaWyB2+8PgpcFunzrXV/E5eIEcsEetrpw7XhEoSS8NI7YGQAfdRYQyWZJQKFvyBRAEZZG9h/tl+8ztuKYW6OWAAAAABJRU5ErkJggg==') ``` -------------------------------- ### Access Nested Menu Items in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Demonstrates how to access nested menu items within a SwiftBar menu structure. This allows for programmatic retrieval of specific items, even those deeply nested. ```python >>> from swiftbarmenu import Menu >>> m = Menu('My menu') >>> item1 = m.add_item('Item 1') >>> item1.add_item('Item 1.1') Item 1.1 >>> item1.add_item('Item 1.2') Item 1.2 >>> item1.add_item('Item 1.3') Item 1.3 >>> item1[2] Item 1.3 ``` -------------------------------- ### Display macOS System Notifications with SwiftBar Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Details how to use the `Notification` class in SwiftBar to trigger macOS system notifications. It covers creating notifications with titles, subtitles, body text, and clickable URLs, as well as options for silent notifications. ```python from swiftbarmenu import Notification # Create and show a notification n = Notification( title="Download Complete", subtitle="file.zip", body="Your download has finished successfully.", href="https://example.com/downloads" ) n.show() # Simple notification with title only Notification("Task completed!").show() # Notification with partial info Notification( title="New Message", subtitle="From: John Doe" ).show() # Silent notification (no sound) Notification( title="Background Sync", body="Data synchronized successfully." ).show(silent=True) # Chain notification creation and display Notification("Alert", "Warning", "Check your settings").show() ``` -------------------------------- ### Add Images to Menu Items with add_image Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Demonstrates the `add_image()` method for incorporating images into menu items. The method automatically handles base64 encoding of image files, which are typically expected to be 16x16 pixels for optimal display in the menu bar. ```python from swiftbarmenu import Menu m = Menu('Image Menu') # Add image from file path (automatically base64 encoded) m.add_image('icons/weather.png', 'Current Weather') m.add_image('icons/settings.png', 'Settings', color='gray') # Add image without text (icon only) m.add_image('icons/status.png', '') m.dump() # The image parameter in output contains base64-encoded image data: # Image Menu # --- # Current Weather|image=iVBORw0KGgo... # Settings|image=iVBORw0KGgo... color=gray # |image=iVBORw0KGgo... ``` -------------------------------- ### Show Silent Notifications in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Explains how to display notifications silently using the SwiftBar `Notification` class by passing `True` to the `.show()` method. This prevents any sound from playing. ```python >>> from swiftbarmenu import Notification >>> n = Notification("Title", "Subtitle", "Body", "https://example.com") >>> n.show(True) # pass True to show silently Notification(title='Title', subtitle='Subtitle', body='Body', href='https://example.com') ``` -------------------------------- ### Access and Modify SwiftBar Menu Structure Source: https://context7.com/sdelquin/swiftbarmenu/llms.txt Explains how to programmatically access and manipulate menu sections in SwiftBar using 'header' and 'body' properties. It demonstrates adding headers, body items, nested items, and clearing specific or all menu items using the 'clear()' method. ```python from swiftbarmenu import Menu m = Menu('Main Title') m.add_header('Header 2') m.add_header('Header 3') m.add_item('Body Item 1') m.add_item('Body Item 2') item1 = m.add_item('Parent') item1.add_item('Child 1') item1.add_item('Child 2') # Access header items (shown cycling in menu bar) print(m.header) # [Main Title, Header 2, Header 3] print(m.header[0].text) # 'Main Title' # Access body items (dropdown menu) print(m.body) # [Body Item 1, Body Item 2, Parent] print(m.body[2].text) # 'Parent' # Access nested items by index print(item1[0].text) # 'Child 1' print(item1[1].text) # 'Child 2' # Clear nested items only item1.clear() print(m.body[2].items) # [] # Clear entire menu m.clear() print(m.header) # [] print(m.body) # [] ``` -------------------------------- ### Add Refresh Actions to SwiftBar Menu in Python Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Shows how to add a 'Refresh' action to a SwiftBar menu. This action triggers a refresh of the current plugin when clicked. It supports custom labels and separators. ```python >>> from swiftbarmenu import Menu >>> m = Menu('My menu') >>> m.add_action_refresh() Refresh... >>> m.add_action_refresh("Reload") Reload >>> m.add_action_refresh(sep=True) Refresh... >>> m.add_action_refresh("Reload", sep=True) Reload >>> m.dump() My menu --- Refresh...|refresh=true terminal=false Reload|refresh=true terminal=false --- Refresh...|refresh=true terminal=false --- Reload|refresh=true terminal=false ``` -------------------------------- ### Add Separator to Menu (Python) Source: https://github.com/sdelquin/swiftbarmenu/blob/main/README.md Illustrates how to add a visual separator line to a SwiftBar menu. Separators can be added implicitly when adding an item with `sep=True` or explicitly using `add_sep()`. ```python from swiftbarmenu import Menu m = Menu('My menu') m.add_item('Item 1') m.add_item('Item 2', sep=True) m.add_item('Item 3') ``` ```python m.add_sep() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.