Bear helper
The script is on GitHub here, and also reproduced below.
Apple Shortcuts app is annoying. It’s full of idiosyncrasies and minor frustrations. I got annoyed trying to use it to do simple things with the wonderful Bear App. So I created Bear Helper, an easy-to-customize menubar app, written in Python. This is what it looks like:
I find it much more satisfying to customize Bear Helper than to use Apple’s Shortcuts app. It’s quicker to write and debug Python code than to work out the idiosyncratic way Shortcuts operates. Bear Helper should be easy to customize and extend, if you’re a techie. These are the types of things it can do for you:
Uses of Bear Helper
Daily journal template
An example daily journal template creates a new note titled with today’s date and a few example headings. It also tags it with nested tags based on the date, which is a really nice way of structuring journal entries. It should be really easy to modify, and add other templates, by just editing the Python code. You could do fancy things like automatically inserting the weather and top news headlines, for example. Here’s what it looks like:
Project template
I spend a lot of time experimenting and learning new things. I try to make everything I do into mini projects, following the PARA method. To make sure I make proper use of my time, and have a record of what I’ve done to refer back to, I have created a Project note. I do a similar thing with my clients and have found it an effective way to make keep a useful record of my work.
Pre-process incompatible markdown before pasting into Bear
This was the main reason I created Bear Helper. If you copy a response from Perplexity.ai, the Markdown it uses for references is not compatible with Bear. The Bear Helper takes the contents of the clipboard and does a bit of search and replace on it, to make it compatible with Bear. Here it is in action:
Insert cleaned Wikipedia article
I haven’t written code for this, but as an example of how Bear Helper could be used, you copy (⌘c) the URL of a wikipedia article, and then have Bear Helper get the article and format it for Bear.
Get answer from ChatGPT API
Another I haven’t coded (yet), but you could write a question in Bear, ⌘c to copy it, then use Bear Helper to send the question via the ChatGPT API, and then paste the response into Bear. You could have different prompts for different types of content. For example, if there is a URL in the clipboard, the Bear Helper could get a summary of the page from ChatGPT.
The code
The code for Bear Helper is below, and also on Github. It uses the marvelous Python package Rumps, which makes it easy to create macOS Python Statusbar apps. You may need to install a few python packages to get this to work. The main one is rumps:
pip install rumps
If you try running the Bear Helper code from within a code editor it probably won’t work. Run from the command line.
# -----------------------------------------------------------------------------
# 🍯 Bear Helper: An easy-to-customize macOS menubar helper for the Bear app
# Written by James Johnson, June 2024
# https://thisisjam.es/bear-helper/ FIXME
# https://github.com/beyond2060/bear-helper
-----------------------------------------------------------------------------
import rumps
# rumps.debug_mode(True)
from datetime import datetime
from AppKit import NSPasteboard, NSStringPboardType
import re
import webbrowser
import urllib.parse
# JOURNAL TEMPLATE ------------------------------------------------------------
= """
journal_template ## 🌟 Daily highlight
*What one thing can I do today that will make it a great day?*
## ⏰ Schedule
### Morning:
### Afternoon:
### Evening:
## 🤔 Reflection
*What went well today? What can I improve?*
## 📅 Plan for tomorrow
*Top priorities for tomorrow.*
---
"""
# PROJECT TEMPLATE ------------------------------------------------------------
= """
project_template ## What am I doing?
## Why?
## Results
## Conclusion
---
## Details
"""
# CODE ------------------------------------------------------------------------
= datetime.today()
today = today.strftime("%d %B %Y")
formatted_date
class BearHelper(rumps.App):
# ABOUT -------------------------------------------------------------------
@rumps.clicked("About Bear Helper")
def about(self, _):
open('https://www.beyond2060.com/bear-helper/')
webbrowser.
# NEW JOURNAL ENTRY -------------------------------------------------------
@rumps.clicked("New journal entry")
def journal(self, _):
= today.strftime( "%A\n")
dayOfWeek
= formatted_date
title = dayOfWeek + journal_template
body = "00 📗 journal/%Y/%m"
tags
newNote(title, body, tags)
# NEW PROJECT -------------------------------------------------------------
@rumps.clicked("New project note")
def project(self, _):
= "Project: TITLE"
title = f"**Date: {formatted_date}**\n" + project_template
body = "03 💥 projects"
tags
newNote(title, body, tags)
# NEW FROM PERPLEXITY -----------------------------------------------------
@rumps.clicked("New note from Perplexity.ai")
def perplexity(self, _):
= NSPasteboard.generalPasteboard()
pb = pb.stringForType_(NSStringPboardType)
pbstring
# Do a regex search and replace on the clipboard contents
# Replace [NUMBER] with "[^NUMBER]
= re.sub(r"\[(\d+)\]", r"[^\1]", pbstring)
body
# If a line starts with [^NUMBER] then replace it with [^NUMBER]:
= re.sub(r"^\[\^(\d+)\]", r"[^\1]:", body, flags=re.MULTILINE)
body = urllib.parse.quote(f"Date: {formatted_date}\n\n" + body)
body
= "TITLE"
title = "perplexity.ai"
tags
newNote(title, body, tags)
# -------------------------------------------------------------------------
def newNote(title, body, tags):
= urllib.parse.quote(title)
title_encoded = urllib.parse.quote(body)
body_encoded = urllib.parse.quote(tags)
tags_encoded
= f"bear://x-callback-url/create?title={title_encoded}&text={body_encoded}&tags={tags_encoded}&clipboard=no&open_note=yes&new_window=yes&float=yes&edit=yes"
xcallback open(xcallback)
webbrowser.
if __name__ == "__main__":
"🍯").run() BearHelper(
If you want me to let you know when I post the next essay use the form below so I can send you an email. Alternatively, follow me on Twitter or LinkedIn.
If you enjoyed this essay please help me promote it by sharing a link to it on your favorite social platform.