Jump to content

Recommended Posts

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 by hujhax
Link to comment

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 by deanishe
Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...