0

Thanks for taking the time to read this. I am calling up a osascript inside of a python script on Mac OS X 10.7.

osascript -e 'tell application "Microsoft PowerPoint" to activate' -e 'tell application "System Events" to key code 124'

Here is the snippet from the script that's erroring:

import os
cmd = """osascript -e 'tell application "Microsoft PowerPoint" to activate' -e 'tell application "System Events" to key code 124'
os.system(cmd)

Here is the error log:

[error] [client 192.168.10.65] 92:96: 
[error] [client 192.168.10.65] syntax error: Expected end of line, etc. but found identifier. (-2741)

Been banging my head for hours, please help or direction is greatly appreciated! =)

Jason S.
  • 13
  • 1
  • 5
  • The snippet you show isn't likely to have been what produced that error; it's not valid Python syntax for one thing. – Ned Deily Sep 17 '12 at 05:10
  • There should be a set of triple quotes at the end of the line where you set the cmd variable. I'm. not sure if that's the problem, but it's definitely a syntax error. – dpk2442 Sep 17 '12 at 07:19

1 Answers1

0

Not sure if you made a copy-paste typo but you should close off the triple quotes on the second line as it is never closed. You might want to include what line and column the 92:96 maps to as well to help people better debug the problem. Also, here's some other suggestions:

  1. Are you supposed to end the 'tell' statement? In all of my scripts I call into with 'osascript' I do.
  2. If that doesn't work, try putting the osascript into a file and execute the file instead of using the '-e' flag.
  3. Use the subprocess module in Python as the os module's way of executing commands is deprecated.
xshoppyx
  • 1,444
  • 1
  • 8
  • 9
  • Now that my newb butt is seeing it. Its actually an from osascript. I tried just using it in a .sh script with apache and gave the same error. I have written the applescript a few different ways to try. `osascript < – Jason S. Sep 17 '12 at 15:32
  • The trailing quotes was an error in cut and paste, but didn't not know that cmd should have triple quotes as well. – Jason S. Sep 17 '12 at 15:42
  • I am guessing the quoting is somehow causing this as that is why it would report it found an identifier. Try using double quotes and escaping literal quotes inside the string with \" – xshoppyx Sep 18 '12 at 06:43