2

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).

enter image description here
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:

enter image description here

But when I execute same script programmatically by NSAppleScript the timeout has no effects and the program waits for 2 minutes:

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. It seems my app is blocked before apple script timeout line [?]
How can I execute apple script same as AppleScript Editor? Any help would be appreciated.

mh taqia
  • 3,506
  • 1
  • 24
  • 35

1 Answers1

1

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. 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".

double_j
  • 1,636
  • 1
  • 18
  • 27