我在python使用AppleScript的模塊寫入一個AppleScript功能和我無法概括如下功能:如何在同一AppleScript命令中使用多個變量?
scpt = applescript.AppleScript('''
on code()
tell application "System Events"
key code 123 using command down
end tell
end code
''')
使得鍵碼和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,你能告訴我你是如何調用該函數的嗎? – mcgrailm