My first Alfred workflow

A hotkey to create a bbedit note with contents of the clipboard

Created: by Pradeep Gowda Updated: Oct 12, 2023 Tagged: alfred · bbedit · automation · chatgpt

Here I’m attempting to write a alfred workflow work with bbedit and document the steps as I go.

2D illustration of a computer keyboard with a highlighted key labeled 'BBEdit Note'. Beside the keyboard, there's a clipboard with text on it, and arrows pointing from the clipboard to the highlighted key, indicating the action of transferring the contents from the clipboard to the BBEdit note.
2D illustration of a computer keyboard with a highlighted key labeled ‘BBEdit Note’. Beside the keyboard, there’s a clipboard with text on it, and arrows pointing from the clipboard to the highlighted key, indicating the action of transferring the contents from the clipboard to the BBEdit note.

ChatGPT Prompt

Tell me how to go about writing a new Alfred (macos automation tool) workflow that can read the contents of the clipboard and create a new note.

ChatGPT Response

Certainly. Here’s a brief step-by-step guide to create an Alfred workflow that reads the clipboard and creates a new note:

  1. Install Alfred with Powerpack: Ensure you’ve installed Alfred and purchased the Powerpack, which unlocks workflows.

  2. Create a New Workflow:

    • Open Alfred’s Preferences.
    • Click on the “Workflows” tab.
    • Click on the + at the bottom and choose “Blank Workflow”.
    • Fill out the details (name, description, etc.) and save.
  3. Add a Hotkey Trigger:

    • Click on the + in the top right corner of the workflow pane.
    • Choose “Triggers” > “Hotkey”.
    • Set your desired hotkey combination.
  4. Add a ‘Run Script’ Action:

    • Click on the + again and choose “Actions” > “Run Script”.
    • For language, choose /bin/bash and enter the script:
text=$(pbpaste)
osascript -e "tell application \"Notes\"
    make new note at folder \"Notes\" with properties {name:\"New Note\", body:$text}
end tell"
  1. Connect the Hotkey to the Script:
    • Drag a line from the right side of the hotkey trigger to the left side of the “Run Script” action.
  2. Save & Test:
    • Save the workflow.
    • Copy some text, activate the hotkey, and a new note should be created in the Notes app.

Done!

My tweaks

The script seems to be for the Apple Notes application, and not for bbedit, so i fixed it to via:

pbpaste | /usr/local/bin/bbedit --clean --view-top

and it works!

Notes:

  1. Assigned Cmd-Shift-b hotkey to trigger this alfred workflow.
  2. Previously I had assigned Cmd-Shift-n as the hotkey under bbedit to trigger the creation of an empty note (without copying the contents of the clipboard)
  3. But then, I had to have bbedit open to start a new note. With this workflow, the Cmd-Shift-b hotkey is “universal” and can start typing notes with one keystroke.

Next steps: 1. figure out how to publish this workflow on a git repo somewhere.

Conclusion

To go fast, go slow at first ;)