-
Notifications
You must be signed in to change notification settings - Fork 8
/
IPMenulet.m
executable file
·58 lines (48 loc) · 1.52 KB
/
IPMenulet.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
//
// IPMenulet.m
// IPMenuletExample
//
// Maintained and updated by Stan James
// https://github.com/wanderingstan/IPMenuletExample
//
// Originally an implementation of the excellent menulet tutorial
// by Andrew Turner, published here:
// http://www.mactech.com/articles/mactech/Vol.22/22.02/Menulet/index.html
#import "IPMenulet.h"
@implementation IPMenulet {
__weak IBOutlet NSMenu *_menuletMenu;
}
- (void) awakeFromNib
{
_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[_statusItem setHighlightMode:YES];
[_statusItem setEnabled:YES];
[_statusItem setToolTip:@"IPMenulet"];
[_statusItem setTarget:self];
// Attach pull-down menu
[_statusItem setMenu:_menuletMenu];
/*
// Title as string
[_statusItem setTitle:[NSString stringWithString:@"0.0.0.0"]];
*/
/*
//Title as Unicode Glyph
[_statusItem setTitle:[NSString stringWithFormat:@"%C",0x2295]];
*/
// Title as Image + String
NSImage * menuIcon = [NSImage imageNamed:@"MenuletIcon"];
[_statusItem setImage:menuIcon];
[_statusItem setTitle:@"000"];
}
- (IBAction) updateIPAddress:(id)sender
{
NSString *ipAddress = [NSString stringWithContentsOfURL:[NSURL URLWithString:
@"http://highearthorbit.com/service/myip.php"] encoding:NSASCIIStringEncoding error:nil];
if (ipAddress != nil) {
[_statusItem setTitle:ipAddress];
}
}
- (IBAction)quitAction:(id)sender {
[[NSApplication sharedApplication] terminate:nil];
}
@end