Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
除掉;选择“应用程序”;应用程序无法启动时的对话框';在AppleScript中找不到_Applescript - Fatal编程技术网

除掉;选择“应用程序”;应用程序无法启动时的对话框';在AppleScript中找不到

除掉;选择“应用程序”;应用程序无法启动时的对话框';在AppleScript中找不到,applescript,Applescript,我需要摆脱那讨厌的对话。我怎样才能做到这一点 我正在尝试获取活动应用程序的窗口标题。有时有些应用程序具有有效的应用程序名称,但当我尝试将其插入AppleScript脚本(用于窗口标题检索)时,会出现该对话框。我只需要忽略这些应用程序,而不必使用该对话框打扰最终用户 提前感谢 这有时是一个问题,因此我们可以通过应用程序的bundle id来定位应用程序,这将消除混淆。这样试试看 set bundleName to "com.apple.TextEdit" -- find out if the a

我需要摆脱那讨厌的对话。我怎样才能做到这一点

我正在尝试获取活动应用程序的窗口标题。有时有些应用程序具有有效的应用程序名称,但当我尝试将其插入AppleScript脚本(用于窗口标题检索)时,会出现该对话框。我只需要忽略这些应用程序,而不必使用该对话框打扰最终用户


提前感谢

这有时是一个问题,因此我们可以通过应用程序的bundle id来定位应用程序,这将消除混淆。这样试试看

set bundleName to "com.apple.TextEdit"

-- find out if the application is running
set appIsRunning to false
tell application "System Events"
    try
        first process whose bundle identifier is bundleName
        set appIsRunning to true
    end try
end tell

if appIsRunning then
    tell application id bundleName
        -- do something
    end tell
end if
这里有一个小脚本可以帮助您找到应用程序的bundle id

try
    tell application "Finder" to set bundleID to id of (choose file)
on error
    return "The chosen file is not an application"
end try
return bundleID
最后,我不确定这是否有助于解决您的问题。如果您的代码中有一行“告诉应用程序无论什么”,而用户的系统中没有任何应用程序,那么该对话框很可能会启动。这就是applescript一直以来的工作方式。苹果已经尝试解决这个问题,大多数程序不再显示“查找应用程序”窗口,但有些程序仍然显示。iPhoto就是我注意到的一个例子

当您将代码作为脚本分发时会发生这种情况,因为当脚本打开时,它必须自行编译。在编译阶段,applescript需要确保代码正确,因此要检查代码,必须检查应用程序的applescript字典。。。这意味着有时必须启动应用程序。然而,有一种可能的解决办法。您必须交付预编译的脚本,这意味着您必须将其作为应用程序而不是脚本分发。此外,必须在应用程序中使用以下构造。因此,换句话说,您将在您的计算机上使用“using terms from”内容预编译脚本,以便用户在运行应用程序时不必检查应用程序的字典

set appName to "TextEdit"

using terms from application "TextEdit"
    tell application appName
        -- do something
    end tell
end using terms from

谢谢“告诉应用程序id bundleName”实际上是我搜索的内容。我有我的Cocoa部分的bundle id。请阅读我文章的其余部分,这可能也会对你产生影响。我在文章中添加了新内容。请注意,当前AppleScript编辑器的脚本默认文件格式-
*.scpt
-也已预编译。另外,我不认为使用
和不使用
中的术语有什么区别(至少在《山狮》上是这样),只要运行一个预编译脚本(无论是带有
osascript
*.scpt
文件还是直接使用
*.app
文件),就应该可以了,因为对话框只会在编译过程中弹出。