本文介绍了Python调用的AppleScript不使用osascript或appscript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法来执行(和获得的结果)从蟒蛇的AppleScript code,而不使用 osascript 命令行实用程序或的(我真的不希望使用(我想?),因为的)?

Is there any way to execute (and obtain the results of) AppleScript code from python without using the osascript command-line utility or appscript (which I don't really want to use (I think?) because it's no longer developed/supported/recommended)?

理由:another我刚刚发布的问题,我描述了一个奇怪的/意外的行为,我通过 osascript 运行AppleScript的一些经历。因为我实际上是从一个python脚本调用它,我想知道是否有一种方法,路线围绕 osascript 干脆,因为这似乎是问题所在 - 但appscript (显而易见的选择吗?)现在看起来风险...

Rationale: in another question I've just posted, I describe a strange/undesired behaviour I'm experiencing with running some AppleScript via osascript. As I'm actually calling it from a python script, I wondered if there was a way to route around osascript altogether, since that seems to be where the problem lies - but appscript (the obvious choice?) looks risky now...

推荐答案

您可以使用PyObjC桥:

You can use the PyObjC bridge:

>>> from Foundation import *
>>> s = NSAppleScript.alloc().initWithSource_("tell app \"Finder\" to activate")
>>> s.executeAndReturnError_(None)

这篇关于Python调用的AppleScript不使用osascript或appscript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 14:04