You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to make this work under Mountain Lion. All seems OK expect one problem. Basically when you click the statusbar icon, the program hangs there for 4-5 seconds. I've identified the culprit but can't seem to find a valid replacement :
Also, I've modified the script a bit the work better with 10.8 :
replace [device getName] by [device name] on line 187 and 309 (deprecated)
replace [device getAddressString] by [device addressString] on line 187 and 310 (deprecated)
modified target build settings to work os 64 bits and 10.8
remove "retain" references (no need to do this with ARC)
added [NSApp activateIgnoringOtherApps:YES]; to showWindow so that prefs windows is always on top
Thanks a lot for your help
Cheers
Here's the full AppController.m
#import "AppController.h"
@implementationAppController
#pragma mark-
#pragma markDelegateMethods-(void)applicationWillTerminate:(NSNotification*)aNotification{[selfstopMonitoring];}-(void)awakeFromNib{NSBundle*bundle=[NSBundlemainBundle];inRangeImage=[[NSImagealloc]initWithContentsOfFile: [bundlepathForResource: @"inRange"ofType: @"png"]];inRangeAltImage=[[NSImagealloc]initWithContentsOfFile: [bundlepathForResource: @"inRangeAlt"ofType: @"png"]];outOfRangeImage=[[NSImagealloc]initWithContentsOfFile: [bundlepathForResource: @"outRange"ofType: @"png"]];outOfRangeAltImage=[[NSImagealloc]initWithContentsOfFile: [bundlepathForResource: @"outOfRange"ofType: @"png"]];priorStatus=OutOfRange;[selfcreateMenuBar];[selfuserDefaultsLoad];}-(void)windowWillClose:(NSNotification*)aNotification{[selfuserDefaultsSave];[selfstopMonitoring];[selfstartMonitoring];}
#pragma mark-
#pragma markAppControllerMethods-(void)createMenuBar{NSMenu*myMenu;NSMenuItem*menuItem;// Menu for status bar itemmyMenu=[[NSMenualloc]init];// Prefences menu itemmenuItem=[myMenuaddItemWithTitle:@"Preferences"action:@selector(showWindow:)keyEquivalent:@""];[menuItemsetTarget:self];// Quit menu item[myMenuaddItemWithTitle:@"Quit"action:@selector(terminate:)keyEquivalent:@""];
// Space on status barstatusItem=[[NSStatusBarsystemStatusBar]statusItemWithLength:NSVariableStatusItemLength];// Attributes of space on status bar[statusItemsetHighlightMode:YES];[statusItemsetMenu:myMenu];[selfmenuIconOutOfRange];}-(void)handleTimer:(NSTimer*)theTimer{if([selfisInRange]){if(priorStatus==OutOfRange){priorStatus=InRange;[selfmenuIconInRange];[selfrunInRangeScript];}}else{if(priorStatus==InRange){
priorStatus =OutOfRange;[selfmenuIconOutOfRange];[selfrunOutOfRangeScript];}}[selfstartMonitoring];}-(BOOL)isInRange{if(device&&[deviceremoteNameRequest:nil]==kIOReturnSuccess)returntrue;returnfalse;}-(void)menuIconInRange{[statusItemsetImage:inRangeImage];[statusItemsetAlternateImage:inRangeAltImage];//[statusItem setTitle:@"O"];}-(void)menuIconOutOfRange{[statusItemsetImage:outOfRangeImage];[statusItemsetAlternateImage:outOfRangeAltImage];// [statusItem setTitle:@"X"];}-(BOOL)newVersionAvailable{NSURL*url=[NSURLURLWithString:@"http://reduxcomputing.com/download/Proximity.plist"];NSDictionary*dict=[NSDictionarydictionaryWithContentsOfURL:url];NSArray*version=[[dictvalueForKey:@"version"]componentsSeparatedByString:@"."];intnewVersionMajor=[[versionobjectAtIndex:0]intValue];intnewVersionMinor=[[versionobjectAtIndex:1]intValue];if(thisVersionMajor<newVersionMajor||thisVersionMinor<newVersionMinor)returnYES;returnNO;}-(void)runInRangeScript{NSAppleScript*script;NSDictionary*errDict;NSAppleEventDescriptor*ae;script=[[NSAppleScriptalloc]initWithContentsOfURL:[NSURLfileURLWithPath:[inRangeScriptPathstringValue]]error:&errDict];ae=[scriptexecuteAndReturnError:&errDict];}-(void)runOutOfRangeScript{NSAppleScript*script;NSDictionary*errDict;NSAppleEventDescriptor*ae;script=[[NSAppleScriptalloc]initWithContentsOfURL:[NSURLfileURLWithPath:[outOfRangeScriptPathstringValue]]error:&errDict];ae=[scriptexecuteAndReturnError:&errDict];}-(void)startMonitoring{if([monitoringEnabledstate]==NSOnState){timer=[NSTimerscheduledTimerWithTimeInterval:[timerIntervalintValue]target:selfselector:@selector(handleTimer:)userInfo:nilrepeats:NO];}}-(void)stopMonitoring{[timerinvalidate];}-(void)userDefaultsLoad{NSUserDefaults*defaults;NSData*deviceAsData;defaults=[NSUserDefaultsstandardUserDefaults];// DevicedeviceAsData=[defaultsobjectForKey:@"device"];if([deviceAsDatalength]>0){
device =[NSKeyedUnarchiverunarchiveObjectWithData:deviceAsData];[deviceNamesetStringValue:[NSStringstringWithFormat:@"%@ (%@)",[devicename],[deviceaddressString]]];if([selfisInRange]){
priorStatus =InRange;[selfmenuIconInRange];}else{
priorStatus =OutOfRange;[selfmenuIconOutOfRange];}}//Timer intervalif([[defaultsstringForKey:@"timerInterval"]length]>0)[timerIntervalsetStringValue:[defaultsstringForKey:@"timerInterval"]];// Out of range script pathif([[defaultsstringForKey:@"outOfRangeScriptPath"]length]>0)[outOfRangeScriptPathsetStringValue:[defaultsstringForKey:@"outOfRangeScriptPath"]];// In range script pathif([[defaultsstringForKey:@"inRangeScriptPath"]length]>0)[inRangeScriptPathsetStringValue:[defaultsstringForKey:@"inRangeScriptPath"]];// Check for updates on startupBOOLupdating=[defaultsboolForKey:@"updating"];if(updating){[checkUpdatesOnStartupsetState:NSOnState];if([selfnewVersionAvailable]){if(NSRunAlertPanel( @"Proximity", @"A new version of Proximity is available for download.",
@"Close", @"Download",nil,nil)==NSAlertAlternateReturn){[[NSWorkspacesharedWorkspace]openURL:[NSURLURLWithString:@"http://reduxcomputing.com/proximity/"]];}}}// Monitoring enabledBOOLmonitoring=[defaultsboolForKey:@"enabled"];if(monitoring){[monitoringEnabledsetState:NSOnState];[selfstartMonitoring];}// Run scripts on startupBOOLstartup=[defaultsboolForKey:@"executeOnStartup"];if(startup){[runScriptsOnStartupsetState:NSOnState];if(monitoring){if([selfisInRange]){[selfrunInRangeScript];}else{[selfrunOutOfRangeScript];}}}}-(void)userDefaultsSave{NSUserDefaults*defaults;NSData*deviceAsData;defaults=[NSUserDefaultsstandardUserDefaults];// Monitoring enabledBOOLmonitoring=([monitoringEnabledstate]==NSOnState ? TRUE : FALSE);[defaultssetBool:monitoringforKey:@"enabled"];// Update checkingBOOLupdating=([checkUpdatesOnStartupstate]==NSOnState ? TRUE : FALSE);[defaultssetBool:updatingforKey:@"updating"];// Execute scripts on startupBOOLstartup=([runScriptsOnStartupstate]==NSOnState ? TRUE : FALSE);[defaultssetBool:startupforKey:@"executeOnStartup"];// Timer interval[defaultssetObject:[timerIntervalstringValue]forKey:@"timerInterval"];// In range script[defaultssetObject:[inRangeScriptPathstringValue]forKey:@"inRangeScriptPath"];// Out of range script[defaultssetObject:[outOfRangeScriptPathstringValue]forKey:@"outOfRangeScriptPath"];// Deviceif(device){deviceAsData=[NSKeyedArchiverarchivedDataWithRootObject:device];[defaultssetObject:deviceAsDataforKey:@"device"];}[defaultssynchronize];}
#pragma mark-
#pragma markInterfaceMethods-(IBAction)changeDevice:(id)sender{IOBluetoothDeviceSelectorController*deviceSelector;deviceSelector=[IOBluetoothDeviceSelectorControllerdeviceSelector];[deviceSelectorrunModal];NSArray*results;results=[deviceSelectorgetResults];if(!results)return;device=[resultsobjectAtIndex:0];[deviceNamesetStringValue:[NSStringstringWithFormat:@"%@ (%@)",[devicename],[deviceaddressString]]];}-(IBAction)checkConnectivity:(id)sender{[progressIndicatorstartAnimation:nil];if([selfisInRange]){[progressIndicatorstopAnimation:nil];NSRunAlertPanel( @"Found", @"Deviceispoweredonandinrange",nil,nil,nil,nil);}else{[progressIndicatorstopAnimation:nil];NSRunAlertPanel( @"NotFound", @"Deviceispoweredofforoutofrange",nil,nil,nil,nil);}}-(IBAction)checkForUpdates:(id)sender{if([selfnewVersionAvailable]){if(NSRunAlertPanel( @"Proximity", @"AnewversionofProximityisavailablefordownload.",
@"Close", @"Download",nil,nil)==NSAlertAlternateReturn){[[NSWorkspacesharedWorkspace]openURL:[NSURLURLWithString:@"http://reduxcomputing.com/proximity/"]];}}else{NSRunAlertPanel( @"Proximity", @"Youhavethelatestversion.", @"Close",nil,nil,nil);}}-(IBAction)donate:(id)sender{[[NSWorkspacesharedWorkspace]openURL:[NSURLURLWithString:@"http://reduxcomputing.com/donate.php"]];}-(IBAction)enableMonitoring:(id)sender{// See windowWillClose: method}-(IBAction)inRangeScriptChange:(id)sender{NSOpenPanel*op=[NSOpenPanelopenPanel];[oprunModalForDirectory:@"~" file:niltypes:[NSArrayarrayWithObject:@"scpt"]];NSArray*filenames=[opfilenames];[inRangeScriptPathsetStringValue:[filenamesobjectAtIndex:0]];}-(IBAction)inRangeScriptClear:(id)sender{[inRangeScriptPathsetStringValue:@""];}-(IBAction)inRangeScriptTest:(id)sender{[selfrunInRangeScript];}-(IBAction)outOfRangeScriptChange:(id)sender{NSOpenPanel*op=[NSOpenPanelopenPanel];[oprunModalForDirectory:@"~" file:niltypes:[NSArrayarrayWithObject:@"scpt"]];NSArray*filenames=[opfilenames];[outOfRangeScriptPathsetStringValue:[filenamesobjectAtIndex:0]];}-(IBAction)outOfRangeScriptClear:(id)sender{[outOfRangeScriptPathsetStringValue:@""];}-(IBAction)outOfRangeScriptTest:(id)sender{[selfrunOutOfRangeScript];}-(void)showWindow:(id)sender{[NSAppactivateIgnoringOtherApps:YES];[prefsWindowmakeKeyAndOrderFront:self];[prefsWindowcenter];[selfstopMonitoring];}
@end
The text was updated successfully, but these errors were encountered:
Hey guys,
I've been trying to make this work under Mountain Lion. All seems OK expect one problem. Basically when you click the statusbar icon, the program hangs there for 4-5 seconds. I've identified the culprit but can't seem to find a valid replacement :
in userdefaultsload function :
Also, I've modified the script a bit the work better with 10.8 :
Thanks a lot for your help
Cheers
Here's the full AppController.m
The text was updated successfully, but these errors were encountered: