kleinfelter Posted February 16, 2015 Posted February 16, 2015 I wrote a workflow to translate clipboard smart-quotes into ordinary ones. It works just fine when run from a shell prompt: pbpaste | textutil -stdin -stdout -convert txt | tr “” \" |tr ’ \' | pbcopy But when I put this into a workflow, my quote marks get doubled and tripled. For example, if I put this in my clipboard: “You’re smart!”and i run the command line listed at the top of this posting, I get: "You're smart!"but if I run the exact same command in an Alfred "run script" workflow, I get: """You""'re smart!"""How do I make Alfred stop messing with the output of my shell script?
Andrew Posted February 16, 2015 Posted February 16, 2015 Could you share the workflow you have created, it may be a simple case of the script escaping in Alfred. [moved to workflow help]
kleinfelter Posted February 16, 2015 Author Posted February 16, 2015 Thanks. I can't see how to attach a file to this forum, so I uploaded it to my dropbox at https://www.dropbox.com/s/lddxkodfq2ens6c/plain-text.alfredworkflow?dl=0 I just created it by using the "Keyword to Script to Notification" template, and set run script to: pbpaste | textutil -stdin -stdout -convert txt | tr “” \" |tr ’ \' | pbcopyI set no escapes, since the script has no input (no {query} parameter)
jdfwarrior Posted February 17, 2015 Posted February 17, 2015 Could you share the workflow you have created, it may be a simple case of the script escaping in Alfred. [moved to workflow help] Not sure the issue behind this one but thought I would mention Andrew... I tried several iterations of this and noticed that if I make a script, we'll call it convert.sh that does nothing but set a variable to the output of pbpaste, echo's that, and then also writes the value to a text file also. If I copy the text mentioned above, then run the script from a terminal, I see the text echoed as expected, but the string that's written to the file (just doing a simple echo $output > log.txt) shows the string like this when I use less to view it <D2>You<D5>re smart!<D3>. There's something weird with those smart quotes. It works as expected when I used a string that didn't contain those things. I wonder if they are getting encoded somehow. The strange thing is though is that, when I call the script from alfred, i'm getting those results. Alfred calls an external script that should do the processing and just returned the cleaned up output. I guess I'm rambling at this point. Just wanted to let you know some of the stuff I tested to see if it could help you track this down.
Andrew Posted February 17, 2015 Posted February 17, 2015 Thanks. I can't see how to attach a file to this forum, so I uploaded it to my dropbox at https://www.dropbox.com/s/lddxkodfq2ens6c/plain-text.alfredworkflow?dl=0 I just created it by using the "Keyword to Script to Notification" template, and set run script to: pbpaste | textutil -stdin -stdout -convert txt | tr “” \" |tr ’ \' | pbcopyI set no escapes, since the script has no input (no {query} parameter) I've had a bit of a play with this and come up with the following workflow: https://dl.dropboxusercontent.com/u/6749767/Alfred/Workflows/Strip%20smart%20quotes.alfredworkflow It allows you to select some text (in e.g. Textedit), hit the hotkey and have the text replaced with the smart quotes removed. Cheers, Andrew
kleinfelter Posted February 17, 2015 Author Posted February 17, 2015 Thank you. I have a theory about what causes the problem with the doubling of the quotes (based on nothing but intuition). They're represented as a UTF-8 multi-byte character sequence. My guess is that somebody, somewhere is upset that multiple bytes get paired up with a single byte. I'm *guessing* that when I run the command from a shell prompt, it is using a different character set that when it is run from Alfred. By using php, your version is picking up PHP's default character set. I wonder if there is a way to specify which character set should be used when a shell is run under Alfred? It figures that the first workflow I'd write would bump up against the margins... Thanks again.
Andrew Posted February 17, 2015 Posted February 17, 2015 I wonder if there is a way to specify which character set should be used when a shell is run under Alfred? You may be right... NSTask constrains the UTF-8 normalisation outside of Alfred's control... I wrote a little command line app which helps in this instance in the following thread which also contains discussion about this issue: http://www.alfredforum.com/topic/2015-encoding-issue/ Let me know if that helps?
deanishe Posted February 19, 2015 Posted February 19, 2015 (edited) If you're using command-line tools, text encoding may very well be the problem. Alfred has an empty environment (like all Mac apps), so default encoding is ASCII, not UTF-8. pbcopy and pbpaste in particular will mangle text if the proper encoding isn't set in its environment. Try adding export LANG=en_US.UTF-8 at the top of your script or use LANG=en_US.UTF-8 your command instead of just your command. Edited February 19, 2015 by deanishe
kleinfelter Posted February 21, 2015 Author Posted February 21, 2015 deanishe - You pegged it. It worked from my Terminal window because I have LANG set. It didn't work from Alfred because it wasn't set in the shell Alfred opened. Setting the encoding to UTF-8 fixed it. Thanks!
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