SwiftBar is bundled with a Plugin Repository. You can access it at Swiftbar → Get Plugins...
If you want to add\remove plugin or have other questions about repository content please refer to this issue.
Creating Plugins
To add a new plugin to SwiftBar, you need to create an executable script following the required format (see below) and put it into Plugin Folder.
Plugin Folder
With the first launch, Swiftbar will ask you to set the Plugin Folder. SwiftBar will try to import every file in this folder as a plugin.
Important:
hidden folders are ignored
nested folders are traversed by SwiftBar, including symlinks
Plugin Naming
Plugin files must adopt the following format:
{name}.{time}.{ext}
name - Anything you want.
time - Refresh interval (optional). Should be a number + duration modifier (see below)
ext - File extension.
Duration modifiers:
ms - milliseconds, e.g. 1ms - refresh every millisecond
s - seconds, e.g. 1s - refresh every second
m - minute, e.g. 10m - refresh every ten minutes
h - hour, e.g. 3h - refresh every three hours
d - day, e.g. 1d - refresh every day
Example filename: date.1m.sh
Whether you are using a plugin from the plugin repository, or creating your own, plugins will initially appear in the menu bar in no pre-determined order. However, you can reorder how they appear by holding down Cmd and dragging them (this process can sometimes also be used on some other non-SwiftBar icons in the menu bar too). Plugin position will be remembered unless you change the name of the plugin file, in which case they'll need to be re-positioned again.
Plugin API
Plugin is an executable script in the language of your choice. When SwiftBar detects a new file in Plugin Folder it makes this file executable if needed and runs it.
Script should produce output (STDOUT) in the required format (see next chapter). Script errors should be redirected to STDERR.
Plugin API is adopted from the BitBar, which means that SwiftBar can run any existing BitBar plugin.
Script Output
When parsing plugin output SwiftBar recognizes the following blocks:
Header: responsible for what you see in the menu bar
Body: responsible for dropdown menu contents
Header is everything before first ---. Each --- after the first one will be interpreted as a menu separator.
You have one or more lines in the header.
The simplest plugin looks like this:
echo"This is Menu Title"
If you provide multiple titles, the provided titles will be cycled in the menu bar and shown in the dropdown menu:
echo"This is a primary Menu Title"echo"This is a secondary Menu Title"echo"This is a n-th Menu Title"echo"---"echo"This is not a Menu Title, this will be showed in the drop-down menu only"
Script output for both header and body is split by line (\n). Each line must follow this format:
<Item Title> | [param = ...]
Where:
"Item Title" can be any string, this will be used as a menu item title.
[param = ...] is an optional set of parameters\modificators. Each parameter is a key-value separated by =. Use | to separate parameters from the title.
Parameters
Text Formatting:
Parameter
Value
Description
color
CSS color or HEX, light_color,dark_color
Sets item text color. If only one color is provided, it is used for both light and dark appearance.
sfcolor
CSS color or HEX, light_color,dark_color
Sets SF Symbol color. If only one color is provided, it is used for both light and dark appearance. If you fame multiple SF Symbols you can provide different colors by adding index, like this sfcolor2
font
macOS font name
Sets font name to use in item text
size
Number
Sets item text size
md
True
Enables markdown support in menu title for **bold** and *italic*
sfsize
Number
Sets size for SF Symbol image embedded in text
length
Number
Trims item text to a provided number of characters. The full title will be displayed in a tooltip.
trim
True
Trims whitespace characters
ansi
True
Enables support of ANSI color codes. Conflicts with:symbolize
emojize
False
Disables parsing of GitHub style Emojis (e.g., :mushroom: into
请发表评论