Jump to content

Invoke Clipboard Manager in the middle of the workflow

Recommended Posts

I have workflow that takes a certain argument. Sometime I want to get this argument from the clipboard manager.


When I hit the shortcut for clipboard manager, Alfred will terminate the current workflow and there is no way to come back to this workflow. Is this possible with Alfred? If not, I would like to convert this to a feature request?


My workaround is to use another clipboard manager or close Alfred and construct the argument in a text editor.




I've been using Alfred since Alfred 2 but this is my first post :)

Edited by jason721b
Link to post

Welcome @jason721b,


Something like this should work:


require 'json'


unless ARGUMENT.nil?
  puts({ items: [{ title: ARGUMENT, arg: ARGUMENT }] }.to_json)
  exit 0

# Use clipboard when no argument given
require 'csv'
require 'open3'

CLIPBOARD_DB = File.join(ENV['HOME'], 'Library/Application Support/Alfred/Databases/clipboard.alfdb')

# The number after `desc limit` determines the number of results
CLIPBOARD_ITEMS = CSV.parse(Open3.capture2(
  '/usr/bin/sqlite3', '-csv', CLIPBOARD_DB,
  'select item from clipboard where dataType = 0 order by ts desc limit 40;'

SCRIPT_FILTER_ITEMS = CLIPBOARD_ITEMS.each_with_object([]) { |item, array| array.push(title: item, arg: item) }

puts({ items: SCRIPT_FILTER_ITEMS }.to_json)


Stick that code in a Script Filter without a Keyword, Argument Optional, and Language set to /usr/bin/ruby. Then add it right before the step where you usually invoke Alfred’s Clipboard History. Depending on how the Workflow is set up, you may need an Argument and Variables Utility as well to save any information of make the argument empty.

What the code does: if you type something and press ↵, it will use that as the argument; if you don’t type, the newest 40 (by default) clipboard items will be shown to you, and you ↵ on any to pass it as the argument.

Edited by vitor
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...