摆脱“选择应用程序”在 AppleScript 中找不到应用程序时的对话框
我需要摆脱那个烦人的对话框。我怎样才能做到这一点?
我正在尝试获取活动应用程序的窗口标题。有时有些应用程序具有有效的应用程序名称,但当我尝试将其插入 AppleScript 脚本(用于检索窗口标题)时,会出现该对话框。我只需要忽略这些应用程序,而不用该对话框打扰最终用户。
预先感谢!
I need to to get rid of that annoying dialog. How can I achieve that?
I'm trying to get an window title of the active application. Sometimes there are applications which has valid app name but when I try to insert it into the AppleScript script(for window title retrieving) that dialog is appeared. I need just to ignore those application without bothering an end-user with that dialog.
Thank in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有时是一个问题,因此我们可以通过应用程序的捆绑 ID 来定位应用程序,这将消除混乱。试试这个方法。
这里有一个小脚本可以帮助您找到应用程序的捆绑 ID。
最后,我不确定这是否能帮助您解决问题。如果您的代码中有“告诉应用程序任何内容”行,并且用户的系统上没有任何应用程序,那么该对话框很可能无论如何都会启动。这就是 applescript 一直以来的工作方式。苹果已尝试解决此问题,大多数程序不再显示“查找应用程序”窗口,但有些程序仍然显示。 iPhoto 是我注意到的一个例子。
当您将代码作为脚本分发时,就会发生这种情况,因为当脚本打开时,它必须自行编译。在编译阶段,applescript 需要确保代码正确,因此要检查代码,必须检查应用程序的 applescript 字典...这意味着有时必须启动应用程序。然而,有一种可能的解决方案。您必须交付预编译的脚本,这意味着您必须将其作为应用程序而不是脚本进行分发。此外,您必须在应用程序中使用以下构造。换句话说,您将使用“using terms from”内容在计算机上预编译脚本,这样用户在运行它时就不必检查应用程序的字典。
That is sometimes an issue, therefore we can target applications by their bundle id, which will remove the confusion. Try it this way.
Here's a little script to help you find the bundle id of an application.
Finally, I'm not sure this will help your problem. If you have a "tell application whatever" line in your code, and the user does not have whatever application on their system, then it's likely that the dialog will launch anyway. That's the way applescript has always worked. Apple has tried to fix this issue and most programs no longer show the "find application" window however some still do. iPhoto is one example I've noticed.
It happens when you distribute your code as a script, because when a script opens it has to compile itself. During the compile phase applescript needs to ensure the code is correct and therefore to check the code the application's applescript dictionary must be checked... which means sometimes the application must be launched. However there is one possible solution. You must deliver your script pre-compiled which means you must distribute it as an application instead of a script. In addition you must use the following construct in the application. So in other words, you will pre-compile the script on your computer with the "using terms from" stuff so the user doesn't have to check the application's dictionary when they run it.