source: trunk/Cocoa/Pester/Source/PSScriptAlert.m@ 636

Last change on this file since 636 was 355, checked in by Nicholas Riley, 17 years ago

English.lproj/MainMenu.nib: Modernize menu and alarm set dialog
layout. Use keyed archiving (10.2+) nib format.

Info-Pester.plist: Moved from old PBX project.

NJRFSObjectSelector.m: Bug fixes from code sent to Joey: remove
incorrect usage of tryToPerform:with:; fix logic error in menu
construction. Work around Cocoa's deciding that the menu font size
needs adjustment when it doesn't - so the menu font size now matches
the button font size, though the position is still off. Don't pop up
a menu if we're disabled. Use IconRefs for menu icons, though not
(yet) for the button icon.

NJRHistoryTrackingComboBox.m: Remove item height adjustment
workaround; it now makes the items too tall.

NJRHotKey.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyField.m: Add a missing [super dealloc] caught by current GCC.

NJRHotKeyManager.m: Add a missing [super dealloc] caught by current
GCC.

NJRIntervalField.m: Fix some type errors.

NJRQTMediaPopUpButton.m: Replace SoundFileManager SPI usage, which
doesn't work in Leopard anyway, with manual enumeration of system
sounds. Start migration to QTKit. Use IconRefs for menu icons.

NJRReadMeController.m: Change source encoding to UTF-8.

NJRSoundManager.m: Fix a type error.

NJRVoicePopUpButton.m: Change source encoding to UTF-8.

NSMenuItem-NJRExtensions.[hm]: Code from ICeCoffEE to use IconRefs for
menu item icons.

PSAlarm.m: Change source encoding to UTF-8.

PSAlarms.m: Fix a signedness mismatch.

PSAlarmsController.m: Change source encoding to UTF-8.

PSAlarmSetController.m: Set keyboard focus after unchecking "Do
script:" and "Play" checkboxes.

PSAlerts.m: Add a missing [super dealloc] caught by current GCC. Fix
a memory leak in property list serialization.

PSPowerManager.[hm]: There's now API for scheduling wakeups; use it
(the old code asserted on startup). To fix: removing scheduled
wakeup. Fix a small type-checking error.

PSPreferencesController.m: Add a missing [super dealloc] caught by
current GCC.

PSScriptAlert.m: Change source encoding to UTF-8.

PSTimeDateEditor.m: Fix a tiny, and one-time, memory leak.

PSTimer.m: Update for new PSPowerManager API.

Pester.pbproj: Deleted; now supporting OS X 10.4+ (up from 10.1,
aiee.)

Pester.xcodeproj: Xcode 2.4+ project, upgraded targets, etc.

SoundFileManager.h: Deleted; this SPI no longer exists in Leopard and
possibly earlier.

File size: 4.3 KB
RevLine 
[34]1//
2// PSScriptAlert.m
3// Pester
4//
5// Created by Nicholas Riley on Sat Oct 26 2002.
6// Copyright (c) 2002 Nicholas Riley. All rights reserved.
7//
8
9#import "PSScriptAlert.h"
10#import "BDAlias.h"
[53]11#import "NSDictionary-NJRExtensions.h"
[34]12
[53]13// property list keys
14static NSString * const PLAlertAlias = @"alias"; // NSData
15
[34]16@implementation PSScriptAlert
17
18+ (PSScriptAlert *)alertWithScriptFileAlias:(BDAlias *)anAlias;
19{
20 return [[[self alloc] initWithScriptFileAlias: anAlias] autorelease];
21}
22
23- (id)initWithScriptFileAlias:(BDAlias *)anAlias;
24{
25 if ( (self = [super init]) != nil) {
26 alias = [anAlias retain];
27 }
28 return self;
29}
30
[53]31- (BDAlias *)scriptFileAlias;
32{
33 return alias;
34}
35
[34]36- (void)triggerForAlarm:(PSAlarm *)alarm;
37{
[53]38 NSString *scriptPath = [alias fullPath];
[34]39
[53]40 if (scriptPath == nil) {
[103]41 NSRunAlertPanel(NSLocalizedString(@"Can't find script", "Title of alert sheet when alias to script didn't resolve"), NSLocalizedString(@"Pester couldn't find the script for the alarm '%@'.", "Message displayed in alert sheet when alias to script didn't resolve"),
[53]42 nil, nil, nil, [alarm message]);
43 } else {
44 NSDictionary *errorInfo;
45 NSAppleScript *script = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: &errorInfo];
46 if (script == nil) {
47 NSString *errorMessage = [errorInfo objectForKey: NSAppleScriptErrorMessage];
48 NSNumber *errorNumber = [errorInfo objectForKey: NSAppleScriptErrorNumber];
49 NSString *appName = [errorInfo objectForKey: NSAppleScriptErrorAppName];
50 if (errorMessage == nil) errorMessage = [errorInfo objectForKey: NSAppleScriptErrorBriefMessage];
51 NSRunAlertPanel(@"Script loading error",
[355]52 @"Pester encountered an error while attempting to load “%@”%@ %@",
[53]53 nil, nil, nil,
54 [[NSFileManager defaultManager] displayNameAtPath: scriptPath],
[355]55 errorMessage == nil ? @"" : [NSString stringWithFormat: @":\n\n%@%@", appName == nil ? @"" : @"“%@” reported an error: ", errorMessage],
[53]56 errorNumber == nil ? @"" : [NSString stringWithFormat: @"(%@)", errorNumber]);
57 } else {
58 NSAppleEventDescriptor *scriptResult = [script executeAndReturnError: &errorInfo];
59 if (scriptResult == nil) {
60 NSString *errorMessage = [errorInfo objectForKey: NSAppleScriptErrorMessage];
61 NSNumber *errorNumber = [errorInfo objectForKey: NSAppleScriptErrorNumber];
62 NSString *appName = [errorInfo objectForKey: NSAppleScriptErrorAppName];
63 if (errorMessage == nil) errorMessage = [errorInfo objectForKey: NSAppleScriptErrorBriefMessage];
64 NSRunAlertPanel(@"Script execution error",
[355]65 @"Pester encountered an error while attempting to execute the script “%@”%@ %@",
[53]66 nil, nil, nil,
67 [[NSFileManager defaultManager] displayNameAtPath: scriptPath],
[355]68 errorMessage == nil ? @"" : [NSString stringWithFormat: @":\n\n%@%@", appName == nil ? @"" : @"“%@” reported an error: ", errorMessage],
[53]69 errorNumber == nil ? @"" : [NSString stringWithFormat: @"(%@)", errorNumber]);
70 }
71 }
[34]72 }
[53]73 [self completedForAlarm: alarm];
[34]74}
[53]75
76- (NSAttributedString *)actionDescription;
77{
78 NSMutableAttributedString *string = [[@"Do script " small] mutableCopy];
79 NSString *scriptName = [alias displayNameWithKindString: NULL];
[103]80 if (scriptName == nil) scriptName = NSLocalizedString(@"<<can't locate script>>", "Script alert description surrogate for script name when alias doesn't resolve");
[53]81 [string appendAttributedString: [scriptName underlined]];
82 return [string autorelease];
83}
84
85#pragma mark property list serialization (Pester 1.1)
86
87- (NSDictionary *)propertyListRepresentation;
88{
89 NSMutableDictionary *plAlert = [[super propertyListRepresentation] mutableCopy];
90 [plAlert setObject: [alias aliasData] forKey: PLAlertAlias];
91 return [plAlert autorelease];
92}
93
94- (id)initWithPropertyList:(NSDictionary *)dict;
95{
96 return [self initWithScriptFileAlias: [BDAlias aliasWithData: [dict objectForRequiredKey: PLAlertAlias]]];
97}
98
[34]99@end
Note: See TracBrowser for help on using the repository browser.