AppleScript 抓取 iOS 模拟器
我想在 OSX 上抓取 iOS 模拟器的屏幕。我希望能够获取在 iOS 模拟器中加载的 UI 屏幕文本,并将其输出到文本文件,我可以在其中进一步操作文本。这可能吗?你们中有人尝试过类似的事情吗?我想在 AppleScript 中执行此操作。
选择 AppleScript 的原因是我的团队已经用 AppleScript 编写了很多自动化任务,我应该能够利用这一点来回收其中一些。事实上,我没有任何 Objective-C 经验,这看起来与我见过的 OO 语言有很大不同,而且我没有时间学习。该工具需要在接下来的两周内启动并运行。
那么这可能吗?
任何正确方向的帮助\指针将不胜感激。
I want to scrape the screen of the iOS Simulator on OSX. I want to be able to take the text of the UI screen that I load up in iOS Simulator and output it to a text file where I can further manipulate the text. Is this possible? have any of you tried something similar before? I would like to do this in AppleScript.
The reason for the AppleScript choice is my team have a lot of their automation tasks scripted in AppleScript already and I should be able to take advantage of this to recycle some of it. That and the fact that I don’t have any Objective-C experience which looks a lot different to OO languages I have seen and I do not have the time to learn. This tool needs to be up and running in the next 2 weeks.
So is this possible?
Any help\pointers in the right direction would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在 applescript 中使用 gui 脚本,这是一项简单的工作。困难的部分是找到对 ui 元素的引用...但如果您使用像 UI 浏览器这样的工具,那么一点也不难。我不运行 iOS 模拟器,但您可以使用 gui 脚本从任何应用程序的前窗口获取内容,因此我认为模拟器窗口没有任何不同。
例如,我正在查看这个 Safari 窗口。我可以从此窗口获取一些文本吗?当然...假设我想使用 gui 脚本获取 url 文本。我可以使用这个...
关于 gui 脚本有一些棘手的事情,但如果你正确使用它,那么它应该不是问题。请注意,从 Safari 窗口中抓取此文本的代码总共花了 2 分钟编写。最困难的部分是获取文本字段参考。
注意:要使 GUI 脚本正常工作,您必须在“通用访问”首选项窗格中启用“启用辅助设备的访问”。
下一部分是操作文本,您可以使用文本项分隔符和其他 applescript 工具在 applescript 中轻松完成此操作。所以总的来说,这份工作对我来说似乎很简单,所需的技能也不是太多。
This is an easy job if you use gui scripting in applescript. The difficult part is finding the references to the ui elements... but it's not difficult at all if you use a tool like UI Browser. I don't run the iOS simulator, but you can get things from the front window of any application using gui scripting, so I don't think a simulator window is any different.
For example, I'm looking at this safari window. Can I get some text from this window? Sure... let's say I want to get the url text using gui scripting. I could use this...
There's some tricky things about gui scripting but if you use it properly then it shouldn't be a problem. Note that this code to scrape this text from the safari window took all of 2 minutes to write. The most difficult part was getting the textfieldReference.
NOTE: for gui scripting to work you have to enable "Enable access for assistive devices" in the Universal Access preference pane.
The next part is manipulating the text which you can do easily right in applescript using text item delimiters and other applescript tools. So overall the job seems simple to me and the required skills aren't too much.