Skip to content

Instantly share code, notes, and snippets.

Last active September 7, 2022 07:04
What would you like to do?
A SwiftBar script to show unread emails in menu-bar

This is a simple SwiftBar script to show unread-emails in menu-bar.

We use it for showing emails count from our error logs. In Django, all the errors are forwarded to an email. This shows the count of unhandled errors.

We archive the emails once the error has been handled.


pip install python-dotenv

Then copy the script in your SwiftBar Scripts folder.

import imaplib
import os
from dotenv import dotenv_values
def _get_unread_emails():
current_path = os.path.dirname(os.path.abspath(__file__))
env_path = os.path.join(current_path, ".env")
env = dotenv_values(env_path)
username = env["EMAIL_ID"]
password = env["PASSWORD"]
# connect to the server
mail = imaplib.IMAP4_SSL("")
mail.login(username, password)
# get count in inbox
status, inbox_count =
return int(inbox_count[0].decode())
if __name__ == "__main__":
unread_count = _get_unread_emails()
if unread_count:
f"⚡{unread_count} | href="
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment