-
Install xbar
- (if you have homebrew installed, you can run
brew install --cask xbar
in your terminal to install it)
- (if you have homebrew installed, you can run
-
Run xbar by double-clicking the application or using Spotlight (cmd space)
- xbar should show up in your mac menubar
-
Open a terminal, navigate to a folder for coding projects, make a new folder for your plugin:
mkdir xbar-jokes-plugin cd xbar-jokes-plugin
-
Make a new file in this folder called
jokes.1h.rb
and paste the following code:#!/usr/bin/env ruby require "http" response = HTTP.get("https://official-joke-api.appspot.com/random_joke") data = response.parse puts data["setup"] puts "---" puts data["punchline"]
-
This example uses the
http
gem to make a web request to an API to get a random joke. You'll need to make sure this gem is installed for this particular script to work (gem install http
). -
The name of the file determines how often it will refresh. 10s - ten seconds, 1m - one minute, 2h - two hours, 1d - a day, etc.
-
(Note): if you're using rbenv, you may need to replace the first line with the full path to your Ruby executable, which you can find by running
which ruby
in your terminal. The first line would look something like this:#!/usr/bin/env /Users/___/.rbenv/shims/ruby
-
-
In your terminal, run the following command to make the file executable
chmod +x jokes.1h.rb
-
In your terminal, run the following command to test the script is executable:
./jokes.1h.rb
- You should see a joke setup and punchline print out in the terminal
-
In your terminal, run the following command to copy your file to the xbar plugins folder:
cp jokes.1h.rb ~/Library/Application\ Support/xbar/plugins
-
In the xbar menubar, click "Refresh all" to run your script
- You should see a random joke setup in the menubar
- If you click on the joke setup, you should see the punchline in the menu below
Read more about creating xbar plugins: https://github.com/matryer/xbar-plugins/blob/main/CONTRIBUTING.md If you need to store API keys in environment variables, read this guide.