hujhax Posted March 22, 2015 Share Posted March 22, 2015 (edited) So I have this Python script: #!/usr/bin/python # -*- coding: iso-8859-15 -*- import os import subprocess p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE) p.stdin.write("٭") p.stdin.close() p.wait() os.system("osascript -e 'tell application \"System Events\" to keystroke \"v\" using {command down}'") If I run that from the Terminal, it outputs the funky little star ("٭") to the console. I've tried putting that exact same Python script into a workflow, though, and using the hotkey only ever outputs "Ÿ≠" instead. What am I doing wrong? =-Peter -- peter rogers @ home | http://www.peterrogers.info When I was 23 myself, it amazed me that T.S. Eliot had written "The Love Song of J. Alfred Prufrock" at 23. Now it makes more sense to me, because of the refrain "There will be time..." Only a young person really believes that, I think. -- 'docbrite' on LiveJournal Edited March 22, 2015 by hujhax Link to comment
deanishe Posted March 23, 2015 Share Posted March 23, 2015 (edited) Alfred uses and expects UTF-8-encoded text only, not ISO-8859-15 (where did you get that from, btw? That's a Windows/Linux encoding, not a Mac one.)Your pbcopy command won't work as expected either, as it will assume ASCII encoding. You need to add an env argument to your Popen call to specify an encoding: env = os.environ.copy() env['LC_CTYPE'] = 'UTF-8' subprocess.Popen(..., env=env, ...) Edited March 23, 2015 by deanishe Link to comment
hujhax Posted March 25, 2015 Author Share Posted March 25, 2015 That fixed it, thanks! The emended code: #!/usr/bin/python # -*- coding: utf-8 -*- import os import subprocess env = os.environ.copy() env['LC_CTYPE'] = 'UTF-8' p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE, env=env) p.stdin.write("٭") p.stdin.close() p.wait() os.system("osascript -e 'tell application \"System Events\" to keystroke \"v\" using {command down}'") Link to comment
hujhax Posted March 25, 2015 Author Share Posted March 25, 2015 Oh, and regarding ISO-8859-15, i just blindly copied that from an example here. Vero 1 Link to comment
deanishe Posted March 25, 2015 Share Posted March 25, 2015 Glad to hear it's working. hujhax 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