-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailComm.m
112 lines (88 loc) · 2.71 KB
/
MailComm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#import "MailComm.h"
@implementation MailComm
- (id)init
{
self = [super init];
composeMessageScript = [self getScript: @"ComposeMessageScript"];
openInboxScript = [self getScript: @"OpenInboxScript"];
checkForNewMessagesScript = [self getScript: @"CheckForNewMessagesScript"];
unreadMessagesInInboxScript = [self getScript: @"CountUnreadMessagesInInboxScript"];
unreadMessagesInAllMailboxesScript = [self getScript: @"CountUnreadMessagesInAllMailboxesScript"];
launchMailScript = [self getScript: @"LaunchMailScript"];
return self;
}
- (int)countUnreadMessagesInInbox
{
int result;
[self executeScriptWithIntReturn: unreadMessagesInInboxScript returningInt:&result];
NSLog(@"Unread message count: %i", result);
return result;
}
- (int)countUnreadMessagesInAllMailboxes
{
int result;
[self executeScriptWithIntReturn: unreadMessagesInAllMailboxesScript returningInt:&result];
return result;
}
- (void)composeMessage
{
[self executeScript: composeMessageScript];
}
- (void)openInbox
{
[self executeScript: openInboxScript];
}
- (void)launchMail
{
[self executeScript: launchMailScript];
}
- (void)checkForNewMessages
{
[self executeScript: checkForNewMessagesScript];
}
- (NSAppleScript *)getScript: (NSString *) scriptName
{
NSString *scriptPath = [[NSBundle mainBundle] pathForResource:scriptName ofType:@"scpt"];
NSURL *url = [NSURL fileURLWithPath: scriptPath];
NSDictionary *errors = [NSDictionary dictionary];
NSAppleScript *newScript = [[NSAppleScript alloc] initWithContentsOfURL: url error: &errors];
if (newScript != nil)
return newScript;
else
return nil;
}
- (void)executeScript: (NSAppleScript *) scriptToExecute
{
NSAppleEventDescriptor *returnDescriptor = NULL;
NSDictionary *errorDict;
returnDescriptor = [scriptToExecute executeAndReturnError: &errorDict];
}
- (void)executeScript: (NSAppleScript *) scriptToExecute withReturningDescriptor: (NSAppleEventDescriptor **) descriptor
{
NSDictionary *errorDict;
*descriptor = [scriptToExecute executeAndReturnError: &errorDict];
// Put error handling stuff here
if (descriptor = nil) {
NSLog(@"There was an error executing the script");
}
}
- (void)executeScriptWithIntReturn: (NSAppleScript *) scriptToExecute returningInt: (int *) result
{
NSAppleEventDescriptor *descriptor;
[self executeScript: scriptToExecute withReturningDescriptor:&descriptor];
if (descriptor == nil) {
NSLog(@"There was an error executing the script");
} else {
// NSLog("Int value of descriptor: %i", [descriptor int32Value]);
// return (int *) [descriptor int32Value];
*result = [descriptor int32Value];
}
}
- (void)dealloc
{
[composeMessageScript release];
[openInboxScript release];
[checkForNewMessagesScript release];
[super dealloc];
}
@end