diff --git a/ControlPlane.xcodeproj/project.pbxproj b/ControlPlane.xcodeproj/project.pbxproj index fbcb3b68e..b2b796065 100644 --- a/ControlPlane.xcodeproj/project.pbxproj +++ b/ControlPlane.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 7392C2D31474C07D00F3CDD5 /* AdiumAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 7392C2D21474C07D00F3CDD5 /* AdiumAction.m */; }; 739492E2146B8018003C94DE /* DisplaySleepTimeAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 739492E1146B8018003C94DE /* DisplaySleepTimeAction.m */; }; 8D01634F0C029913004AD8DB /* DNDArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D01634D0C029913004AD8DB /* DNDArrayController.m */; }; 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; @@ -205,7 +206,9 @@ 29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 32CA4F630368D1EE00C91783 /* ControlPlane_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ControlPlane_Prefix.pch; path = Source/ControlPlane_Prefix.pch; sourceTree = ""; }; - 739492E0146B8018003C94DE /* DisplaySleepTimeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; name = DisplaySleepTimeAction.h; path = Source/DisplaySleepTimeAction.h; sourceTree = ""; }; + 7392C2D11474C07D00F3CDD5 /* AdiumAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AdiumAction.h; path = Source/AdiumAction.h; sourceTree = ""; }; + 7392C2D21474C07D00F3CDD5 /* AdiumAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AdiumAction.m; path = Source/AdiumAction.m; sourceTree = ""; }; + 739492E0146B8018003C94DE /* DisplaySleepTimeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplaySleepTimeAction.h; path = Source/DisplaySleepTimeAction.h; sourceTree = ""; }; 739492E1146B8018003C94DE /* DisplaySleepTimeAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DisplaySleepTimeAction.m; path = Source/DisplaySleepTimeAction.m; sourceTree = ""; }; 8D01634C0C029913004AD8DB /* DNDArrayController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DNDArrayController.h; path = Source/DNDArrayController.h; sourceTree = ""; }; 8D01634D0C029913004AD8DB /* DNDArrayController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = DNDArrayController.m; path = Source/DNDArrayController.m; sourceTree = ""; }; @@ -750,6 +753,8 @@ DD8274EB14114CFF0098FA6E /* Application Actions */ = { isa = PBXGroup; children = ( + 7392C2D11474C07D00F3CDD5 /* AdiumAction.h */, + 7392C2D21474C07D00F3CDD5 /* AdiumAction.m */, DDDF1C291411D49300DB0018 /* DefaultBrowserAction.h */, DDDF1C2A1411D49300DB0018 /* DefaultBrowserAction.m */, 8D3453C10C18E5C1006011D0 /* IChatAction.h */, @@ -1024,6 +1029,7 @@ "/System/Library/CoreServices/System Events.app", /Applications/iTunes.app, "/System/Library/CoreServices/Printer Setup Utility.app", + /Applications/Adium.app, ); name = "Generate Script Bridge Headers"; outputPaths = ( @@ -1032,6 +1038,7 @@ "$(DERIVED_FILE_DIR)/System Events.h", "$(DERIVED_FILE_DIR)/iTunes.h", "$(DERIVED_FILE_DIR)/Printer Setup Utility.h", + "$(DERIVED_FILE_DIR)/Adium.h", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -1114,6 +1121,7 @@ DD5BD20B141614C4007BA88C /* JSONKit.m in Sources */, DA922E9D144FC95200920B40 /* ToggleInternetSharingAction.m in Sources */, 739492E2146B8018003C94DE /* DisplaySleepTimeAction.m in Sources */, + 7392C2D31474C07D00F3CDD5 /* AdiumAction.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/Action.m b/Source/Action.m index c585be447..02b3a8959 100644 --- a/Source/Action.m +++ b/Source/Action.m @@ -146,6 +146,7 @@ + (NSString *)creationHelpText #pragma mark - +#import "AdiumAction.h" #import "DefaultPrinterAction.h" #import "DefaultBrowserAction.h" #import "DesktopBackgroundAction.h" @@ -187,6 +188,7 @@ - (id)init return nil; classes = [[NSArray alloc] initWithObjects: + [AdiumAction class], [DefaultPrinterAction class], [DefaultBrowserAction class], [DesktopBackgroundAction class], @@ -224,6 +226,7 @@ - (id)init if (NO) { // Purely for the benefit of 'genstrings' + NSLocalizedString(@"AdiumStatus", @"Action type"); NSLocalizedString(@"DefaultPrinter", @"Action type"); NSLocalizedString(@"DefaultBrowser", @"Action type"); NSLocalizedString(@"DesktopBackground", @"Action type"); diff --git a/Source/AdiumAction.h b/Source/AdiumAction.h new file mode 100644 index 000000000..efa66bd50 --- /dev/null +++ b/Source/AdiumAction.h @@ -0,0 +1,24 @@ +// +// AdiumAction.h +// ControlPlane +// +// Created by Dustin Rue on 11/16/11. +// Copyright (c) 2011. All rights reserved. +// + +#import "Action.h" + +@interface AdiumAction : Action { + NSString *status; +} + +- (id)initWithDictionary:(NSDictionary *)dict; +- (void)dealloc; +- (NSMutableDictionary *)dictionary; + +- (NSString *)description; +- (BOOL)execute:(NSString **)errorString; ++ (NSString *)helpText; ++ (NSString *)creationHelpText; + +@end \ No newline at end of file diff --git a/Source/AdiumAction.m b/Source/AdiumAction.m new file mode 100644 index 000000000..d2a42c2a2 --- /dev/null +++ b/Source/AdiumAction.m @@ -0,0 +1,103 @@ +// +// AdiumAction.m +// ControlPlane +// +// Created by Dustin Rue on 11/16/11. +// Copyright (c) 2011. All rights reserved. +// + +#import "AdiumAction.h" +#import +#import "Adium.h" +#import "DSLogger.h" + +@implementation AdiumAction + +- (id)init +{ + if (!(self = [super init])) + return nil; + + status = [[NSString alloc] init]; + + return self; +} + +- (id)initWithDictionary:(NSDictionary *)dict +{ + if (!(self = [super initWithDictionary:dict])) + return nil; + + status = [[dict valueForKey:@"parameter"] copy]; + + return self; +} + +- (void)dealloc +{ + [status release]; + + [super dealloc]; +} + +- (NSMutableDictionary *)dictionary +{ + NSMutableDictionary *dict = [super dictionary]; + + [dict setObject:[[status copy] autorelease] forKey:@"parameter"]; + + return dict; +} + +- (NSString *)description +{ + return [NSString stringWithFormat:NSLocalizedString(@"Setting Adium status to '%@'.", @""), status]; +} + +- (BOOL) execute: (NSString **) errorString { + // inspiration comes from: + // http://stackoverflow.com/questions/4416335/applescript-is-cool-can-i-do-the-same-thing-in-plain-objective-c + @try { + + AdiumApplication *adium = [SBApplication applicationWithBundleIdentifier: @"com.adiumX.adiumX"]; + + // no sense in changing Adium if it isn't running + if (![adium isRunning]) + return YES; + + AdiumStatus *newStatus = [[[adium classForScriptingClass:@"status"] alloc] init]; + + // not entirely sure how this part works, but you basically need + // to add the newStatus scripting class to the SBApplication/AdiumApplication + // object in order for it to become useable + [[adium statuses] addObject:newStatus]; + + [newStatus setSaved:NO]; + [newStatus setTitle:status]; + + [newStatus setStatusMessage:(AdiumRichText *)status]; + + + + [adium setGlobalStatus:newStatus]; + + } @catch (NSException *e) { + *errorString = NSLocalizedString(@"Couldn't set Adium status!", @"In AdiumAction"); + DSLog(@"error was %@", e); + return NO; + } + + return YES; +} + ++ (NSString *)helpText +{ + return NSLocalizedString(@"The parameter for Adium actions is the status message to set.", @""); +} + ++ (NSString *)creationHelpText +{ + return NSLocalizedString(@"Set Adium status message to", @""); +} + +@end