Ignore:
Timestamp:
01/02/03 05:30:03 (21 years ago)
Author:
Nicholas Riley
Message:

Updated for Pester 1.1a5 (very limited release).

Pester 1.1a4 was never released.

Location:
trunk/Cocoa/Pester/Source
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source

    • Property svn:ignore
      •  

        old new  
        11build
         2.gdb_history
  • trunk/Cocoa/Pester/Source/PSScriptAlert.m

    r34 r53  
    99#import "PSScriptAlert.h"
    1010#import "BDAlias.h"
    11 #import "NDAppleScriptObject.h"
     11// XXX remove #import "NDAppleScriptObject.h"
     12#import "NSDictionary-NJRExtensions.h"
     13
     14// property list keys
     15static NSString * const PLAlertAlias = @"alias"; // NSData
    1216
    1317@implementation PSScriptAlert
     
    2630}
    2731
     32- (BDAlias *)scriptFileAlias;
     33{
     34    return alias;
     35}
     36
    2837- (void)triggerForAlarm:(PSAlarm *)alarm;
    2938{
    30     NDAppleScriptObject *as = [NDAppleScriptObject appleScriptObjectWithContentsOfFile: [alias fullPath]];
     39    NSString *scriptPath = [alias fullPath];
    3140
    32     if (as != nil) {
    33         [as execute];
     41    if (scriptPath == nil) {
     42        NSRunAlertPanel(@"CanÕt find script", @"Pester couldnÕt find the script for the alarm Ò%@Ó.",
     43                        nil, nil, nil, [alarm message]);
     44    } else {
     45        NSDictionary *errorInfo;
     46        NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: &errorInfo];
     47        if (script == nil) {
     48            NSString *errorMessage = [errorInfo objectForKey: NSAppleScriptErrorMessage];
     49            NSNumber *errorNumber = [errorInfo objectForKey: NSAppleScriptErrorNumber];
     50            NSString *appName = [errorInfo objectForKey: NSAppleScriptErrorAppName];
     51            if (errorMessage == nil) errorMessage = [errorInfo objectForKey: NSAppleScriptErrorBriefMessage];
     52            NSRunAlertPanel(@"Script loading error",
     53                            @"Pester encountered an error while attempting to load Ò%@Ó%@ %@",
     54                            nil, nil, nil,
     55                            [[NSFileManager defaultManager] displayNameAtPath: scriptPath],
     56                            errorMessage == nil ? @"" : [NSString stringWithFormat: @":\n\n%@%@", appName == nil ? @"" : @"Ò%@Ó reported an error: ", errorMessage],
     57                            errorNumber == nil ? @"" : [NSString stringWithFormat: @"(%@)", errorNumber]);
     58        } else {
     59            NSAppleEventDescriptor *scriptResult = [script executeAndReturnError: &errorInfo];
     60            if (scriptResult == nil) {
     61                NSString *errorMessage = [errorInfo objectForKey: NSAppleScriptErrorMessage];
     62                NSNumber *errorNumber = [errorInfo objectForKey: NSAppleScriptErrorNumber];
     63                NSString *appName = [errorInfo objectForKey: NSAppleScriptErrorAppName];
     64                if (errorMessage == nil) errorMessage = [errorInfo objectForKey: NSAppleScriptErrorBriefMessage];
     65                NSRunAlertPanel(@"Script execution error",
     66                                @"Pester encountered an error while attempting to execute the script Ò%@Ó%@ %@",
     67                                nil, nil, nil,
     68                                [[NSFileManager defaultManager] displayNameAtPath: scriptPath],
     69                                errorMessage == nil ? @"" : [NSString stringWithFormat: @":\n\n%@%@", appName == nil ? @"" : @"Ò%@Ó reported an error: ", errorMessage],
     70                                errorNumber == nil ? @"" : [NSString stringWithFormat: @"(%@)", errorNumber]);
     71            }
     72        }
    3473    }
     74    [self completedForAlarm: alarm];
    3575}
     76
     77- (NSAttributedString *)actionDescription;
     78{
     79    NSMutableAttributedString *string = [[@"Do script " small] mutableCopy];
     80    NSString *scriptName = [alias displayNameWithKindString: NULL];
     81    if (scriptName == nil) scriptName = @"ÇcanÕt locate scriptÈ";
     82    [string appendAttributedString: [scriptName underlined]];
     83    return [string autorelease];
     84}
     85
     86#pragma mark property list serialization (Pester 1.1)
     87
     88- (NSDictionary *)propertyListRepresentation;
     89{
     90    NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
     91    [plAlert setObject: [alias aliasData] forKey: PLAlertAlias];
     92    return [plAlert autorelease];
     93}
     94
     95- (id)initWithPropertyList:(NSDictionary *)dict;
     96{
     97    return [self initWithScriptFileAlias: [BDAlias aliasWithData: [dict objectForRequiredKey: PLAlertAlias]]];
     98}
     99
    36100@end
Note: See TracChangeset for help on using the changeset viewer.