Skip to content

Commit

Permalink
Really basic implementation for passing scripting commands through UR…
Browse files Browse the repository at this point in the history
…L scheme pomodoro://.

An example: pomodoro://start
Maps DIRECTLY to the commands in Pomodoro/src/<url>Command.(h,m)
Doesn't (yet) pass arguments.
  • Loading branch information
partlyhuman committed Nov 23, 2012
1 parent c2dd292 commit 66fb909
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Pomodoro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
69ED6411133BB31F003F59BA /* SmartTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED6410133BB31F003F59BA /* SmartTimer.m */; };
69ED6414133BB502003F59BA /* SmartTimerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 69ED6413133BB502003F59BA /* SmartTimerTests.m */; };
69FCF747135729DD003862DC /* ringBreak.wav in Resources */ = {isa = PBXBuildFile; fileRef = 69FCF746135729DD003862DC /* ringBreak.wav */; };
DB8AF4F4165EEB0F0039DA49 /* OpenUrlCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = DB8AF4F3165EEB0F0039DA49 /* OpenUrlCommand.m */; };
DCAF37C8164AE360003764C9 /* getToDoListFromReminders.applescript in Sources */ = {isa = PBXBuildFile; fileRef = DCAF37C7164AE360003764C9 /* getToDoListFromReminders.applescript */; };
DCAF37CC164AFB6C003764C9 /* addTodoToReminders.applescript in Sources */ = {isa = PBXBuildFile; fileRef = DCAF37CB164AFB6C003764C9 /* addTodoToReminders.applescript */; };
DCAF37CD164B074D003764C9 /* getToDoListFromReminders.applescript in Resources */ = {isa = PBXBuildFile; fileRef = DCAF37C7164AE360003764C9 /* getToDoListFromReminders.applescript */; };
Expand Down Expand Up @@ -430,6 +431,8 @@
69ED6412133BB502003F59BA /* SmartTimerTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmartTimerTests.h; sourceTree = "<group>"; };
69ED6413133BB502003F59BA /* SmartTimerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SmartTimerTests.m; sourceTree = "<group>"; };
69FCF746135729DD003862DC /* ringBreak.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = ringBreak.wav; sourceTree = "<group>"; };
DB8AF4F2165EEB0F0039DA49 /* OpenUrlCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OpenUrlCommand.h; path = src/OpenUrlCommand.h; sourceTree = "<group>"; };
DB8AF4F3165EEB0F0039DA49 /* OpenUrlCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OpenUrlCommand.m; path = src/OpenUrlCommand.m; sourceTree = "<group>"; };
DCAF37C7164AE360003764C9 /* getToDoListFromReminders.applescript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.applescript; path = getToDoListFromReminders.applescript; sourceTree = "<group>"; };
DCAF37CB164AFB6C003764C9 /* addTodoToReminders.applescript */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.applescript; path = addTodoToReminders.applescript; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -824,6 +827,8 @@
69D17E23136C103800F5D922 /* InternalInterruptCommand.m */,
69D17E1F136C101800F5D922 /* ResumeCommand.h */,
69D17E20136C101800F5D922 /* ResumeCommand.m */,
DB8AF4F2165EEB0F0039DA49 /* OpenUrlCommand.h */,
DB8AF4F3165EEB0F0039DA49 /* OpenUrlCommand.m */,
);
name = Scriptable;
sourceTree = "<group>";
Expand Down Expand Up @@ -1154,6 +1159,7 @@
69D17E24136C103800F5D922 /* InternalInterruptCommand.m in Sources */,
DCAF37C8164AE360003764C9 /* getToDoListFromReminders.applescript in Sources */,
DCAF37CC164AFB6C003764C9 /* addTodoToReminders.applescript in Sources */,
DB8AF4F4165EEB0F0039DA49 /* OpenUrlCommand.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 12 additions & 1 deletion Pomodoro/Pomodoro-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBuildNumber</key>
<integer>42</integer>
<integer>60</integer>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
Expand All @@ -22,6 +22,17 @@
<string>1.3.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Pomodoro App</string>
<key>CFBundleURLSchemes</key>
<array>
<string>pomodoro</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1.3.5</string>
<key>LSApplicationCategoryType</key>
Expand Down
7 changes: 7 additions & 0 deletions Pomodoro/src/OpenUrlCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <Foundation/Foundation.h>

@interface OpenUrlCommand : NSScriptCommand

- (id)performDefaultImplementation;

@end
30 changes: 30 additions & 0 deletions Pomodoro/src/OpenUrlCommand.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#import "OpenUrlCommand.h"

@implementation OpenUrlCommand

- (id)performDefaultImplementation
{
NSURL *url = [NSURL URLWithString:[self directParameter]];
if (!url) return @"A parameter is required, e.g. pomodoro://start";

//accept any capitalization
NSString *command = [[url host] capitalizedString];

//Special case for CamelCase commands (if there were more than say, two, we'd consider doing this more intelligently.
if ([command isEqualToString:@"Externalinterrupt"]) command = @"ExternalInterrupt";
if ([command isEqualToString:@"Internalinterrupt"]) command = @"InternalInterrupt";
//Disallow this possible loop.
if ([command isEqualToString:@"Openurl"]) command = nil;

//TODO pass along arguments from query.

Class CommandClass = NSClassFromString([NSString stringWithFormat:@"%@Command", command]);
if (CommandClass && [CommandClass isSubclassOfClass:[NSScriptCommand class]])
{
return [[[CommandClass alloc] init] performDefaultImplementation];
}

return [NSString stringWithFormat:@"Didn't understand the command '%@'", [url host]];
}

@end
10 changes: 9 additions & 1 deletion Pomodoro/src/Pomodoro.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@
<cocoa class="ResumeCommand"/>
<result type="text" description="Action result"/>
</command>

</suite>

<suite name="Internet Suite" code="gurl" description="control Pomodoro from URL scheme">
<command name="open location" code="GURLGURL" description="Run a Pomodoro command from a URI">
<cocoa class="OpenUrlCommand"/>
<direct-parameter description="the URL to open" type="text" optional="yes"/>
<result type="text" description="Action result"/>
</command>
</suite>

</dictionary>

0 comments on commit 66fb909

Please sign in to comment.