【发布时间】:2013-10-14 09:16:20
【问题描述】:
我正在使用 applescript 模块在 python 中编写一个 applescript 函数,但无法概括以下函数:
scpt = applescript.AppleScript('''
on code()
tell application "System Events"
key code 123 using command down
end tell
end code
''')
这样keycode和keydown变量就可以作为输入参数,像这样:
scpt = applescript.AppleScript('''
on code(kc, extras)
tell application "System Events"
key code kc extras
end tell
end code
''')
但我收到以下运行时错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "example.py", line 28, in <module>
''')
File "build/bdist.macosx-10.7-intel/egg/applescript/__init__.py", line 49, in __init__
applescript.ScriptError: Expected end of line but found application constant or consideration. (-2741) range=410-414
所以我认为我的语法有问题。
我使用的是 Mac 0SX 10.7.5,python 2.7.1。
编辑
此代码位于名为 example.py 的 python 模块中,这里的代码与模块中的代码完全相同:
import applescript
scpt = applescript.AppleScript('''
on code(kc, extras)
tell application "System Events"
key code kc extras
end tell
end code
''')
我从命令行调用它如下:
$ python
Python 2.7.1 (r271:86832, Aug 5 2011, 03:30:24)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import example as e
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "example.py", line 9, in <module>
''')
File "build/bdist.macosx-10.7-intel/egg/applescript/__init__.py", line 49, in __init__
applescript.ScriptError: Expected end of line but found identifier. (-2741) range=90-96
第 9 行是我模块的最后一行 -- ''')。
【问题讨论】:
-
哪一行是 28,你能告诉我你是怎么调用这个函数的吗?
标签: python variables python-2.7 applescript keycode