简体   繁体   English

超时在NSAppleScript中不起作用

[英]Timeout has no effect in NSAppleScript

I have a simple apple script as follows: 我有一个简单的苹果脚本,如下所示:

tell application id "com.adobe.InDesign"
    set sel to selection
end tell

This script is executed fine, but when the InDesign displaying Save Confirm Dialog , if I execute the script, It waits for 2 minutes (Default apple script timeout). 该脚本执行得很好,但是当InDesign显示“ 保存确认对话框”时 ,如果我执行该脚本,它将等待2分钟(默认的Apple脚本超时)。

在此处输入图片说明
Save Confirm Dialog 保存确认对话框

Thus I specified timeout as follows: 因此,我将超时指定如下:

tell application id "com.adobe.InDesign"
    with timeout of 0.2 seconds
        set sel to selection
    end timeout
end tell

Now If I execute above script in AppleScript Editor every thing is as I expected: 现在,如果我在AppleScript Editor中执行上述脚本,那么一切都会如我所愿:

在此处输入图片说明

But when I execute same script programmatically by NSAppleScript the timeout has no effects and the program waits for 2 minutes: 但是,当我通过NSAppleScript以编程方式执行相同的脚本时,超时没有任何效果,程序将等待2分钟:

NSDictionary *errorDict;
NSString *script = 
    @"tell application id \"com.adobe.InDesign\"\n"
    @"  with timeout of 0.2 second\n"
    @"      set sel to selection\n"
    @"  end timeout\n"
    @"end tell\n"
    ;    
NSAppleScript* scr = [[NSAppleScript alloc] initWithSource: script];
[scr executeAndReturnError: &errorDict];

Additional description: 附加说明:
When my cocoa code is executing (when my app is blocked) If I execute same script in AppleScript Editor then my cocoa code is unblocked before 2 minutes timeout. 当我的可可代码正在执行时(当我的应用程序被阻止时)如果我在AppleScript编辑器中执行相同的脚本,那么我的可可代码在2分钟超时之前将被解除阻止。 It seems my app is blocked before apple script timeout line [?] 看来我的应用在Apple脚本超时行[?]之前被阻止了
How can I execute apple script same as AppleScript Editor ? 如何执行与AppleScript编辑器相同的Apple脚本? Any help would be appreciated. 任何帮助,将不胜感激。

Building your script and saving as an Application should fix this. 构建脚本并将其另存为应用程序应该可以解决此问题。 It should be the same script but just add on run and end run at the beginning and end of the script. 它应该是相同的脚本,但只需on run脚本的开头和结尾添加on runend run The way to do this is when you go to save, at the bottom of the save menu, there should be a file format dropdown. 这样做的方法是在保存时,在“保存”菜单的底部,应该有一个文件格式下拉列表。 Select the "Application" option and save. 选择“应用程序”选项并保存。

I have noticed this will nullify the "default Applescript timeout". 我注意到这将使“默认Applescript超时”无效。

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

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