jason721b Posted March 12, 2021 Share Posted March 12, 2021 (edited) 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 March 12, 2021 by jason721b Link to comment
vitor Posted March 12, 2021 Share Posted March 12, 2021 (edited) Welcome @jason721b, Something like this should work: require 'json' ARGUMENT = ARGV[0] unless ARGUMENT.nil? puts({ items: [{ title: ARGUMENT, arg: ARGUMENT }] }.to_json) exit 0 end # 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;' ).first).flatten 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 March 18, 2021 by vitor luckman212 and jason721b 1 1 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now