Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adium actions #463

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion ControlPlane.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (); }; };
Expand Down Expand Up @@ -205,7 +206,9 @@
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32CA4F630368D1EE00C91783 /* ControlPlane_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ControlPlane_Prefix.pch; path = Source/ControlPlane_Prefix.pch; sourceTree = "<group>"; };
739492E0146B8018003C94DE /* DisplaySleepTimeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; name = DisplaySleepTimeAction.h; path = Source/DisplaySleepTimeAction.h; sourceTree = "<group>"; };
7392C2D11474C07D00F3CDD5 /* AdiumAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AdiumAction.h; path = Source/AdiumAction.h; sourceTree = "<group>"; };
7392C2D21474C07D00F3CDD5 /* AdiumAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AdiumAction.m; path = Source/AdiumAction.m; sourceTree = "<group>"; };
739492E0146B8018003C94DE /* DisplaySleepTimeAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DisplaySleepTimeAction.h; path = Source/DisplaySleepTimeAction.h; sourceTree = "<group>"; };
739492E1146B8018003C94DE /* DisplaySleepTimeAction.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = DisplaySleepTimeAction.m; path = Source/DisplaySleepTimeAction.m; sourceTree = "<group>"; };
8D01634C0C029913004AD8DB /* DNDArrayController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DNDArrayController.h; path = Source/DNDArrayController.h; sourceTree = "<group>"; };
8D01634D0C029913004AD8DB /* DNDArrayController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = DNDArrayController.m; path = Source/DNDArrayController.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 = (
Expand All @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
3 changes: 3 additions & 0 deletions Source/Action.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ + (NSString *)creationHelpText

#pragma mark -

#import "AdiumAction.h"
#import "DefaultPrinterAction.h"
#import "DefaultBrowserAction.h"
#import "DesktopBackgroundAction.h"
Expand Down Expand Up @@ -187,6 +188,7 @@ - (id)init
return nil;

classes = [[NSArray alloc] initWithObjects:
[AdiumAction class],
[DefaultPrinterAction class],
[DefaultBrowserAction class],
[DesktopBackgroundAction class],
Expand Down Expand Up @@ -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");
Expand Down
24 changes: 24 additions & 0 deletions Source/AdiumAction.h
Original file line number Diff line number Diff line change
@@ -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 <ActionWithString> {
NSString *status;
}

- (id)initWithDictionary:(NSDictionary *)dict;
- (void)dealloc;
- (NSMutableDictionary *)dictionary;

- (NSString *)description;
- (BOOL)execute:(NSString **)errorString;
+ (NSString *)helpText;
+ (NSString *)creationHelpText;

@end
103 changes: 103 additions & 0 deletions Source/AdiumAction.m
Original file line number Diff line number Diff line change
@@ -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 <ScriptingBridge/SBApplication.h>
#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