Jump to content

Accessing clipboard history inside a Workflow

Recommended Posts

On a Workflow with multiple manual steps, you may find it useful to access recent clipboard history in order to pass along previously copied data to the next stage.

But if you switch context to the Clipboard History Viewer, you lose your place in the Workflow. To avoid that, you can load your history into a Script Filter and place it between the relevant steps of your Workflow. This post provides working code to do just that.

Things to note:

  • This works by directly accessing Alfred’s clipboard history SQLite database, so it can be considered a hacky solution. Use at your own risk. That said, it only reads data.
  • By default it shows the 40 most recent items from the clipboard history. Look for LIMIT 40 in the script to change that value.
  • Only text entries are considered. Everything else is ignored.
  • The code does not limit you to the clipboard contents. If you type something, that will be used instead.

Paste the code in a Script Filter without a Keyword, Argument Optional, and Language set to /usr/bin/zsh --no-rcs.


if [[ -n "${1}" ]]
  /usr/bin/osascript -l JavaScript -e 'function run(argv) {
    return JSON.stringify({ items: [{ title: argv[0], arg: argv[0] }] })
  }' "${1}"

  exit 0

/usr/bin/sqlite3 \
  "${HOME}/Library/Application Support/Alfred/Databases/clipboard.alfdb" \
    'title', item,
    'arg', item)))
    SELECT item
    FROM clipboard
    WHERE dataType IS 0
    ORDER by ts
    LIMIT 40)"


Link to comment
Share on other sites

  • vitor locked this topic
This topic is now closed to further replies.
  • Create New...