Running AppleScript on Python : "Syntax Error: Expected end of line but found end of script."

Running AppleScript on Python : "Syntax Error: Expected end of line but found end of script."

当我运行下面的代码时,我一直得到这个:

Syntax Error: Expected end of line but found end of script error

我对 AppleScript 比较陌生。 这是我第一次尝试这样做并且还没有能够实现它。让我知道我是否遗漏了什么,或者是否有其他方法可以做到这一点。我见过的几个类似的例子都是单行 applescripts,所以我想知道这是否是问题所在。

import subprocess

def chooseFile():                                   
    args = []
    args.append('osascript')
    args.append('-e')
    args.append('tell application "System Events"')
    args.append('delay 1')
    args.append('keystroke "G" using {command down,  shift down}')
    args.append('delay 2')
    args.append('keystroke "/Users/username/Desktop/folder/image.jpg"')
    args.append('delay 1')
    args.append('keystroke return')
    args.append('delay 1')
    args.append('keystroke return')
    args.append('end tell')    
    subprocess.call(args)
    
chooseFile()

根据 this,您的脚本的每一行都需要一个 -e。 例如:

args.extend(["-e",'tell application "System Events"'])