bvp663 Posted November 28, 2016 Posted November 28, 2016 I've been trying to tackle a workflow but I keep running into an issue with how Alfred is handling clipboard contents. The Workflow The workflow is designed to take content copied from a spreadsheet (two columns, multiple rows) and injest data from both columns into a url in Chrome. 1234 5678 9101112 13141516 The script is designed to inject the items into a url, for example https://mywebsit.com/{field1}/blahblah/{field2} Here's the script: CLIPBOARD=$(pbpaste -Prefer txt) while read LINE ; do FIELD1=$(echo $LINE | cut -d ' ' -f 1) FIELD2=$(echo $LINE | cut -d ' ' -f 2) open -a "/Applications/Google Chrome.app" "https://mywebsite.com/${FIELD1}/blahblahblah/${FIELD2}/" open -a "/Applications/Google Chrome.app" "https://mywebsite.com/${FIELD1}/beepboop/${FIELD2}" done < <(echo $query) I got it working, but it will only open tabs for the first row and won't run through any additional rows. From what I can tell, this seems to be Alfred's fault in how it handles clipboard contents. If I run `pbaste` in Terminal the clipboard contents show up in columns and rows as expected. However if I tell Alfred to send to LOGGER how it's reading clipboard contents, they all show up in a single line. e.g. When I run pbpaste in Terminal: 1234 5678 9101112 13141516 e.g. How Alfred interprets pbpaste in the script: 1234 5678 9101112 13141516 Is there anything I'm missing here? Is this a known issue with Alfred or is there a different way to approach the problem?
deanishe Posted November 28, 2016 Posted November 28, 2016 (edited) The script doesn't make sense. CLIPBOARD=$(pbpaste -Prefer txt) but done < <(echo $query) Where does $query come from? Should that line read done <<(echo $CLIPBOARD)? Alfred doesn't "interpret" your scripts in any way. It passes them straight to whichever program you've specified to run them (with the single exception of replacing {query} if you have it set up that way). However, it's important to remember that Alfred doesn't use your shell environment. In particular, if you call, say, python expecting that to be /usr/local/bin/python, your script may not work because /usr/local/bin isn't in PATH in Alfred (or any Mac application). You'll get /usr/bin/python instead. Edited November 28, 2016 by deanishe
vitor Posted November 28, 2016 Posted November 28, 2016 (edited) Don’t echo or cat to pipes or use <(echo. There are easier and more correct ways: cat "{{input_file}}" | command # can be expressed as command < "{{input_file}}" echo "{{input_text}}" | command # can be expressed as command <<< "{{input_text}}" And why save CLIPBOARD, even? I wouldn’t be surprised if bash itself was mangling the multi-line variable. You can scrape CLIPBOARD and just: while … done < $(pbpaste) Edited November 28, 2016 by vitor
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