简体   繁体   English

使用Python驱动Applescript脚本的最简单解决方案

[英]Simplest solution to use Python to drive an Applescript script

Since Apple has already integrated a full UI automation tool like Applescript (ancient, yes...ugly, yes; but can't find anything better), I was wondering if I can run a Applescript script, inside Python unit test class. 由于Apple已经集成了像Applescript这样的完整的UI自动化工具(很古老,是的……丑陋的,是的;但是找不到更好的东西),我想知道是否可以在Python单元测试类中运行Applescript脚本。

I did find an abandoned project that was integrating AS and Python, but I would like to use something that is stable and reliable; 我确实找到了一个集成了AS和Python的废弃项目,但是我想使用稳定可靠的东西。 and most of all, easy to implement. 最重要的是,易于实施。

I did look at pyObjC and it is quite a pain to deal with (I know basically nothing about Objective-C), so the last resort that I did try, is to use AS, but I have no way to get results about actions, unless I use something like Python. 我确实看过pyObjC,要解决它是很痛苦的(我对Objective-C基本一无所知),所以我尝试的最后一招是使用AS,但是我无法获得有关操作的结果,除非我使用Python之类的东西。 Unless there is an easier way, that I do not know 除非有更简单的方法,否则我不知道

py-applescript provides an easy-to-use wrapper around PyObjC and NSAppleScript for calling AS handlers and converting Python arguments and results to and from their AS equivalents automatically. py- NSAppleScript为PyObjC和NSAppleScript提供了一个易于使用的包装器,用于调用AS处理程序并自动将Python参数和结果与AS等效项相互转换。 (Strictly speaking I no longer support py-appscript either - as with py-appscript I'm no longer willing to throw good time after bad - but the py-applescript code is simple enough that any Python user can figure out how to fix or improve it for herself if necessary.) (严格来说,我也不再支持py-appscript-就像py-appscript一样,我不再愿意花很多时间在糟糕的事上-但是py-applescript代码非常简单,任何Python用户都可以弄清楚如何修复或如有必要,请自己进行改进。)

Alternatively, you can avoid the extra module dependency by using both PyObjC and AppleScriptObjC to bridge all the way from Python to AppleScript , though it does require some basic understanding of both ObjC bridges to do it. 另外,尽管同时使用PyObjC和AppleScriptObjC来桥接从Python到AppleScript的所有方法 ,也可以避免额外的模块依赖性,尽管这样做确实需要对两个ObjC桥接器有一些基本的了解。

The only other option for doing Apple event automation in Python is to use OS X's crappy Scripting Bridge framework via PyObjC, but since SB is riddled with a ton of incomprehensible bugs, defects, and omissions of its own, that's about the last thing you want to inject into your test scripts. 在Python中执行Apple事件自动化的唯一其他选择是通过PyObjC使用OS X糟糕的Scripting Bridge框架,但是由于SB充满了大量无法理解的错误,缺陷和遗漏,这就是您想要做的最后一件事注入到您的测试脚本中。

... ...

OTOH, if you're only doing graphical UI testing, then calling OS X's low-level Accessibility APIs via System Events.app via AppleScript via Python is arguably overkill anyway, and you may want to look around for existing Python GUI automation libraries that just wrap OS X's Accessibility APIs directly. OTOH,如果您在进行图形UI测试,那么通过Python通过AppleScript通过System Events.app调用OS X的低级可访问性API无疑是过头的,并且您可能想看看现有的Python GUI自动化库直接包装OS X的辅助功能API。 eg Here's a useful-looking list , although I can't vouch for its accuracy or completeness, or the quality of the libraries it links to. 例如, 这是一个看起来有用的列表 ,尽管我不能保证其准确性或完整性,也不保证其链接的库的质量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM