Python 2 和 AppleScript.对话框提示和默认答案



这里只是我用来读取Mac系统概述文件的XML数据的Python代码的一小部分,目的是将数据添加到数据库,而无需手动复制/粘贴详细信息。

具体来说,这段代码会提示用户输入"文章编号"以保存给定的".spx"(系统概述报告(。

import subprocess
exampleString = "12345"
theText = subprocess.check_output(['osascript', '-e',
                              r'''set theText to text returned of (display dialog "Enter new Article Number here:
                               nnElse just press OK" default answer "" with title "Hardware Paster v1.0" with icon 2)'''
                              ])

"theText"将转到口述spx文件的名称。

我想在AppleScript提示符内设置"默认答案"的值,并在主python脚本中设置另一个变量的值(在本例中为"exampleString"(。"12345"在这里只是占位符文本。

最终目标是最大限度地减少最终用户的数据输入。

感谢您的帮助。

只是字符串格式,你很好!

>>> exampleString = "world"
>>> 'hello there "{}"!'.format(exampleString)
'hello there "world"!'

并应用于您的程序:

exampleString = "12345"
template = r'''set theText to text returned of (display dialog "Enter new Article Number here:
nnElse just press OK" default answer "{}" with title "Hardware Paster v1.0" with icon 2)'''
theText = subprocess.check_output(
    ['osascript', '-e', template.format(exampleString)])

最新更新