I'm trying to make a python script pass characters from a text file as keystrokes into OSX. The text file is formatted as a column of characters:
Which is being read into a list (called lines). This bit seems to work, as when I type lines[3], for example, the third character is printed, as expected.
I'm now trying to use applescript to pass this character as a keystroke to OSX, using the following:
import os
for f in xrange ( VALUE ):
osascript -e 'tell application "System Events" to keystroke linesf]'
It doesn't seem happy about the list[f] part (syntax error, carat is beneath the final apostrophe). I suspect it's because the variable f is not available to this command, for some reason, but I'm not certain. Could anybody give any advice? I know that the bit in the for loop needs to be indented, but this dialogue won't let me indent it, for some reason. It is correct in the script that I am testing.
Thank in advance.
Edit:
Those were typos, it should be lines, not list, the colon should be there, and it should be indented. After fixing all of this, I have the same result. I can't just iterate through the list, this is only an excerpt of the for loop, it needs to be structured this way for the rest to work.
How do I fix the line beginning osascript?
I got this by editing the accepted answer from this question, by the way: Is there a sendKey for Mac in Python?