luckman212 Posted February 3, 2019 Share Posted February 3, 2019 (edited) I'm trying to make a workflow that accepts a single parameter "N" (a number) and then uses that to merge the last N clipboards, and paste that to the frontmost app. Let's call it "clipmerge" and it uses keyword `cm`. e.g. "cm9" would take {clipboard:0} {clipboard:1} ... {clipboard:8} and merge them. Anyone got any ideas on how to achieve this? edit: I figured out my own solution... click here Edited February 3, 2019 by luckman212 bivalvegruff 1 Link to comment
luckman212 Posted February 3, 2019 Author Share Posted February 3, 2019 (edited) Figured out a way - not sure if it's the "right" way but, it works well enough. I used a couple of bash scripts to validate/filter the input as well as loop & process the output. If you want to have a look... (link removed, scroll down for the new version) Edited February 3, 2019 by luckman212 bivalvegruff 1 Link to comment
bivalvegruff Posted February 3, 2019 Share Posted February 3, 2019 Nicely done, this makes the clipboard a lot more useful! I noticed that if I only have two clips in the clipboard and execute cm3 (more than I have), it messes up the clips, if you want to do some touching up. It's good as it is though. Link to comment
luckman212 Posted February 3, 2019 Author Share Posted February 3, 2019 Thanks. Yes, I noticed the same thing after posting. I'm working on a fix for if you type a number that exceeds the number of clips you have in the history. Link to comment
luckman212 Posted February 3, 2019 Author Share Posted February 3, 2019 Well, that was a long & winding road. I'm new to Alfred so I'm still figuring things out. I tried everything I could to avoid using a /tmp file but this was the only way that worked. Everything else—using variables, trying to process the clipboard buffers from within the workflow itself, using external triggers etc, all failed. This seems to be due to the way Alfred processes the query buffer as it passes through the workflow. Internally, a reference like `{clipboard:11}` will always return that exact text (e.g. if used in a comparison statement from bash or python) -- it only converts it to the actual clipboard value during OUTPUT actions such as Large Type or Write Text File. The 2nd problem is, if `{clipboard:11}` contains a NULL (empty) value, instead of returning BLANK (which would be expected), Alfred insists on instead outputting the dynamic placeholder itself. So, if you have only 5 clips and you ask for 10 to be merged, the last 5 will be written out as just `{clipboard:6}, {clipboard:7}...` etc. TL;DR I could not find a reliable way to test for "empty" values and omit them from the output other than using Write Text File and then processing it with sed. This works fine though, and the script cleans up the /tmp file after itself and is pretty quick about it. If anyone knows a better way I'm all ears. But I think this is something that would have to be fixed in Alfred itself. Here's the new version: changes omits empty strings from output if you request > clips than exist in the history configurable MIN_CLIPS and MAX_CLIPS variables added notifications for success/failure https://github.com/luckman212/clipmerge-alfred-workflow/blob/master/README.md bivalvegruff and JJJJ 2 Link to comment
P-D Posted August 28, 2022 Share Posted August 28, 2022 (edited) Thanks for your efforts and comments about merging clipboards, which I have looked into from time to time, without any feasible solution. I could not imagine how extremely simple this turned out to be. Due to Alfred's dynamic placeholders and brace expansion in shell script (and not even bothering to save the argument $1 in a new variable), this is the only line in my current workflow, merging the $1 + 1 most recent clipboards (including {clipboard:0} and 'reversed', i.e. in the same order as copied): echo '{clipboard:'{$1..0}'}\n' Edited August 30, 2022 by P-D Link to comment
sudopeople Posted October 12, 2022 Share Posted October 12, 2022 On 8/28/2022 at 2:36 AM, P-D said: this is the only line in my current workflow echo '{clipboard:'{$1..0}'}\n' Can you share your workflow? There's a detail or two missing, I assume. 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