Skip to content

Commit

Permalink
Add shortcut Opt+D to upload selected Finder item
Browse files Browse the repository at this point in the history
* If multiple items are selected, the first will be uploaded
  • Loading branch information
moshee committed Mar 30, 2014
1 parent 82e49ed commit 31bac53
Show file tree
Hide file tree
Showing 4 changed files with 862 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Airlift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
4E90AEE518E697FC00A50247 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4E90AEE118E697E700A50247 /* Sparkle.framework */; };
4E90AEEB18E7CFE100A50247 /* dsa_pub.pem in Resources */ = {isa = PBXBuildFile; fileRef = 4E90AEEA18E7CFE100A50247 /* dsa_pub.pem */; };
4E90AEF318E7EB4A00A50247 /* ALUploadHistoryItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E90AEF218E7EB4A00A50247 /* ALUploadHistoryItem.m */; };
4E90AEF618E877F400A50247 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E90AEF518E877F400A50247 /* ScriptingBridge.framework */; };
4EF567EA18BA8C5F0060A66A /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EF567E918BA8C5F0060A66A /* Cocoa.framework */; };
4EF567F418BA8C5F0060A66A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4EF567F218BA8C5F0060A66A /* InfoPlist.strings */; };
4EF567F618BA8C5F0060A66A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EF567F518BA8C5F0060A66A /* main.m */; };
Expand Down Expand Up @@ -43,6 +44,8 @@
4E90AEEA18E7CFE100A50247 /* dsa_pub.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = dsa_pub.pem; sourceTree = "<group>"; };
4E90AEF118E7EB4A00A50247 /* ALUploadHistoryItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALUploadHistoryItem.h; sourceTree = "<group>"; };
4E90AEF218E7EB4A00A50247 /* ALUploadHistoryItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ALUploadHistoryItem.m; sourceTree = "<group>"; };
4E90AEF418E8717600A50247 /* Finder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Finder.h; sourceTree = "<group>"; };
4E90AEF518E877F400A50247 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = System/Library/Frameworks/ScriptingBridge.framework; sourceTree = SDKROOT; };
4EF567E618BA8C5F0060A66A /* Airlift.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Airlift.app; sourceTree = BUILT_PRODUCTS_DIR; };
4EF567E918BA8C5F0060A66A /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
4EF567EC18BA8C5F0060A66A /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -72,6 +75,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4E90AEF618E877F400A50247 /* ScriptingBridge.framework in Frameworks */,
4EF60A9D18E3F905003AB75F /* Carbon.framework in Frameworks */,
4EF5682818BAA15B0060A66A /* Security.framework in Frameworks */,
4EF567EA18BA8C5F0060A66A /* Cocoa.framework in Frameworks */,
Expand Down Expand Up @@ -103,6 +107,7 @@
4EF567E818BA8C5F0060A66A /* Frameworks */ = {
isa = PBXGroup;
children = (
4E90AEF518E877F400A50247 /* ScriptingBridge.framework */,
4E90AEE118E697E700A50247 /* Sparkle.framework */,
4EF60A9C18E3F905003AB75F /* Carbon.framework */,
4EF5682718BAA15B0060A66A /* Security.framework */,
Expand All @@ -125,6 +130,7 @@
4EF567EF18BA8C5F0060A66A /* Airlift */ = {
isa = PBXGroup;
children = (
4E90AEF418E8717600A50247 /* Finder.h */,
4EF567FB18BA8C5F0060A66A /* ALAppDelegate.h */,
4EF567FC18BA8C5F0060A66A /* ALAppDelegate.m */,
4EF5682218BA94000060A66A /* ALPreferenceViewController.h */,
Expand Down
6 changes: 5 additions & 1 deletion Airlift/ALAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
- (void)removeUploadFromHistory:(ALUploadHistoryItem*)upload;
- (ALPreferenceViewController*)prefs;

enum HotkeyAction { HotkeyTakeScreenshot = 0, HotkeyTakeFullScreenshot };
enum HotkeyAction {
HotkeyTakeScreenshot = 0,
HotkeyTakeFullScreenshot,
HotkeyUploadFromFinder
};

@end
36 changes: 36 additions & 0 deletions Airlift/ALAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// license that can be found in the LICENSE file.

#import "ALAppDelegate.h"
#import "Finder.h"

@interface ALAppDelegate () {
NSMenu* menu;
Expand Down Expand Up @@ -60,6 +61,11 @@ - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
RegisterEventHotKey(kVK_ANSI_3, optionKey + shiftKey, hotKeyID,
GetApplicationEventTarget(), 0, &hotKeyRef);

hotKeyID.signature = 'uplf';
hotKeyID.id = HotkeyUploadFromFinder;
RegisterEventHotKey(kVK_ANSI_D, optionKey, hotKeyID,
GetApplicationEventTarget(), 0, &hotKeyRef);

[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];

[[SUUpdater sharedUpdater] setDelegate:self];
Expand Down Expand Up @@ -184,6 +190,33 @@ + (void)uploadScreenshot:(NSArray*)additionalArgs {
[upload doUpload];
}

+ (void)uploadFileFromFinder {
FinderApplication* finder =
[SBApplication applicationWithBundleIdentifier:@"com.apple.Finder"];
if (![finder isRunning]) {
NSLog(@"Finder is not running");
return;
}

SBElementArray* selection = [[finder selection] get];
if ([selection count] == 0) {
NSLog(@"Finder selection is empty");
return;
}

NSArray* URLs = [selection arrayByApplyingSelector:@selector(URL)];
NSString* first = [URLs firstObject];
NSURL* fileURL = [NSURL URLWithString:first];
if (fileURL == nil) {
NSLog(@"couldn't convert FinderItem URL '%@' to NSURL", first);
return;
}

ALUploadManager* upload = [[ALUploadManager alloc] initWithFileURL:fileURL];
[[[ALAppDelegate sharedAppDelegate] dropZone] setCurrentUpload:upload];
[upload doUpload];
}

OSStatus
handleHotkey(EventHandlerCallRef nextHandler, EventRef anEvent, void* userData) {
EventHotKeyID hotKeyID;
Expand All @@ -197,6 +230,9 @@ + (void)uploadScreenshot:(NSArray*)additionalArgs {
case HotkeyTakeFullScreenshot:
[ALAppDelegate uploadScreenshot:nil];
break;
case HotkeyUploadFromFinder:
[ALAppDelegate uploadFileFromFinder];
break;
}

return noErr;
Expand Down
Loading

0 comments on commit 31bac53

Please sign in to comment.