hyperknot Posted December 14, 2017 Share Posted December 14, 2017 (edited) I'm trying to write a workflow, which would clean a C/C++ file, via astyle command line program, using clipboard copy and paste. It has to be the simplest workflow, yet I cannot make it preserve new lines. What is the best way to output something into stdin and read from there? So far I'm trying this in a bash script (with argv) but it removes all the new lines characters: echo -n $1 | /usr/local/bin/astyle https://www.dropbox.com/s/bkffs7j6nchwbog/astyle clean.alfredworkflow?dl=0 Edited December 14, 2017 by hyperknot Link to comment
hyperknot Posted December 14, 2017 Author Share Posted December 14, 2017 So far I realised that it's the $1 argv bit which removes my newlines. How can I preserve it? As a hack, I simply did pbpaste | /usr/local/bin/astyle and it seems to work, but how would I do it normally? Link to comment
deanishe Posted December 14, 2017 Share Posted December 14, 2017 It's not the $1 that's messing with your input, it's Alfred's default setting. Hit the Run Behaviour button in the Script (Filter) configuration and change the setting for Argument to not strip whitespace. Link to comment
hyperknot Posted December 14, 2017 Author Share Posted December 14, 2017 Do you mean changing the current flow from: keyword -> > ({clipboard}) -> run script -> copy to clipboard to script filter -> copy to clipboard ? I was using the above flow because it was in the templates for clipboard processing. Link to comment
deanishe Posted December 14, 2017 Share Posted December 14, 2017 Oh, you’re using Run Script. I don’t know what Alfred does with the input to that, or if it alters the clipboard data. In any case, you could ignore Alfred’s clipboard support and replace your “echo” with “pbpaste”: pbpaste -Prefer txt | /usr/local/bin/astyle The -Prefer flag tells pbpaste to emit plaintext (there may be a richtext version on the clipboard, too). Link to comment
hyperknot Posted December 14, 2017 Author Share Posted December 14, 2017 Thanks, I've settled on pbpaste then! Link to comment
deanishe Posted December 14, 2017 Share Posted December 14, 2017 Does it work any better? Link to comment
hyperknot Posted December 14, 2017 Author Share Posted December 14, 2017 With pbpaste it work perfectly. I tried rewriting it to a script filter, but I couldn't even launch it with a keyword, when I pressed Return it just disappeared and offered me to google my keyword instead. Probably a totally newbie setting somewhere, but at the end I went back to run script. Link to comment
deanishe Posted December 15, 2017 Share Posted December 15, 2017 59 minutes ago, hyperknot said: I tried rewriting it to a script filter Script Filters are for showing items in Alfred. If your Script Filter doesn't print XML/JSON in the format understood by Alfred (or if it crashes), Alfred shows its Fallback Searches. You don't want a Script Filter. (I couldn't download your workflow, as I was replying from my phone earlier.) Link to comment
hyperknot Posted December 15, 2017 Author Share Posted December 15, 2017 I only thought about using Script Filter as that was the only place where I found your recommended option of not stripping whitespaces. I've updated the shared workflow file, it works for me quite nice as it is now. deanishe 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