Changeset 53 for trunk/Cocoa/Pester/Source/PSScriptAlert.m
- Timestamp:
- 01/02/03 05:30:03 (21 years ago)
- Location:
- trunk/Cocoa/Pester/Source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source
- Property svn:ignore
-
old new 1 1 build 2 .gdb_history
-
- Property svn:ignore
-
trunk/Cocoa/Pester/Source/PSScriptAlert.m
r34 r53 9 9 #import "PSScriptAlert.h" 10 10 #import "BDAlias.h" 11 #import "NDAppleScriptObject.h" 11 // XXX remove #import "NDAppleScriptObject.h" 12 #import "NSDictionary-NJRExtensions.h" 13 14 // property list keys 15 static NSString * const PLAlertAlias = @"alias"; // NSData 12 16 13 17 @implementation PSScriptAlert … … 26 30 } 27 31 32 - (BDAlias *)scriptFileAlias; 33 { 34 return alias; 35 } 36 28 37 - (void)triggerForAlarm:(PSAlarm *)alarm; 29 38 { 30 N DAppleScriptObject *as = [NDAppleScriptObject appleScriptObjectWithContentsOfFile: [alias fullPath]];39 NSString *scriptPath = [alias fullPath]; 31 40 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 } 34 73 } 74 [self completedForAlarm: alarm]; 35 75 } 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 36 100 @end
Note:
See TracChangeset
for help on using the changeset viewer.