I am stuck. I have SublimeText plug-in that I wrote run code in Stata (a statistics package). After preparing the file, I used to do this:
cmd = """osascript<< END
tell application "stata"
activate
open POSIX file "%s"
end tell
END""" % dofile_path
os.system(cmd)
... where dofile_path is the path to the stata file I wish to run.
Unfortunately, something changed with a Stata update and this now opens the Stata editor rather than the main package. I therefore have tried to re-write this using System Events and the clipboard.
cmd = """osascript -e "activate application \"StataMP\"" -e "tell app \"System Events\" to set the clipboard to \"do sublime2stata.do\" " -e "tell app \"System Events\" to keystroke \"v\" using {command down}" -e "tell app \"System Events\" to keystroke return" end tell"""
I have tried this as a multiline script like this too ...
cmd = """osascript<< END
tell application \"StataMP\"
activate
end tell
tell application \"System Events\"
keystroke \"1\" using {command down}
set the clipboard to \"do %s\"
keystroke \"v\" using {command down}
keystroke return
end tell
say "finished"
END""" % dofile_path
os.system(cmd)
The keystroke "1" using {command down}
is just there to make sure the command window of stata is selected.
The problem is that nothing happens! The file is generated, the script runs (because it says "finished" OK) but nothing is pasted into the stata command window.
Can anyone see my mistake?