aboutsummaryrefslogtreecommitdiffstats
path: root/Copy Mailto
diff options
context:
space:
mode:
Diffstat (limited to 'Copy Mailto')
-rw-r--r--Copy Mailto/AppDelegate.h20
-rw-r--r--Copy Mailto/AppDelegate.m42
-rw-r--r--Copy Mailto/Assets.xcassets/AppIcon.appiconset/Contents.json58
-rw-r--r--Copy Mailto/Base.lproj/MainMenu.xib125
-rw-r--r--Copy Mailto/CopyMailto.entitlements5
-rw-r--r--Copy Mailto/DefaultURLHandler.h15
-rw-r--r--Copy Mailto/DefaultURLHandler.m24
-rw-r--r--Copy Mailto/Info.plist43
-rw-r--r--Copy Mailto/QuitButton.h16
-rw-r--r--Copy Mailto/QuitButton.m22
-rw-r--r--Copy Mailto/main.m19
11 files changed, 389 insertions, 0 deletions
diff --git a/Copy Mailto/AppDelegate.h b/Copy Mailto/AppDelegate.h
new file mode 100644
index 0000000..7ba86b3
--- /dev/null
+++ b/Copy Mailto/AppDelegate.h
@@ -0,0 +1,20 @@
+//
+// AppDelegate.h
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface AppDelegate : NSObject <NSApplicationDelegate> {
+ IBOutlet NSWindow *_window;
+ IBOutlet NSTextField *_email_address;
+}
+
+- (void)handleURLEvent:(NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (IBAction)copyEmailToClipboard:(id)sender;
+
+@end
diff --git a/Copy Mailto/AppDelegate.m b/Copy Mailto/AppDelegate.m
new file mode 100644
index 0000000..752b716
--- /dev/null
+++ b/Copy Mailto/AppDelegate.m
@@ -0,0 +1,42 @@
+//
+// AppDelegate.m
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import "AppDelegate.h"
+
+const NSUInteger MAILTO_INDEX = 7;
+
+@implementation AppDelegate
+
+- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
+ [[NSAppleEventManager sharedAppleEventManager]
+ setEventHandler:self
+ andSelector:@selector(handleURLEvent:withReplyEvent:)
+ forEventClass:kInternetEventClass
+ andEventID:kAEGetURL];
+}
+
+- (void)handleURLEvent:(NSAppleEventDescriptor *)event
+ withReplyEvent: (NSAppleEventDescriptor *)replyEvent
+{
+ NSString *url = [[event paramDescriptorForKeyword:keyDirectObject]
+ stringValue];
+ [_email_address setStringValue:[url substringFromIndex:MAILTO_INDEX]];
+}
+
+- (IBAction)copyEmailToClipboard:(id)sender
+{
+ NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
+ [pasteboard clearContents];
+ [pasteboard writeObjects:
+ [NSArray arrayWithObject:
+ [_email_address stringValue]]];
+
+ [NSApp terminate:self];
+}
+
+@end
diff --git a/Copy Mailto/Assets.xcassets/AppIcon.appiconset/Contents.json b/Copy Mailto/Assets.xcassets/AppIcon.appiconset/Contents.json
new file mode 100644
index 0000000..2db2b1c
--- /dev/null
+++ b/Copy Mailto/Assets.xcassets/AppIcon.appiconset/Contents.json
@@ -0,0 +1,58 @@
+{
+ "images" : [
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "16x16",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "32x32",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "128x128",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "256x256",
+ "scale" : "2x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "1x"
+ },
+ {
+ "idiom" : "mac",
+ "size" : "512x512",
+ "scale" : "2x"
+ }
+ ],
+ "info" : {
+ "version" : 1,
+ "author" : "xcode"
+ }
+} \ No newline at end of file
diff --git a/Copy Mailto/Base.lproj/MainMenu.xib b/Copy Mailto/Base.lproj/MainMenu.xib
new file mode 100644
index 0000000..263596f
--- /dev/null
+++ b/Copy Mailto/Base.lproj/MainMenu.xib
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="13771" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" customObjectInstantitationMethod="direct">
+ <dependencies>
+ <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="13771"/>
+ <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+ </dependencies>
+ <objects>
+ <customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
+ <connections>
+ <outlet property="delegate" destination="Voe-Tx-rLC" id="GzC-gU-4Uq"/>
+ </connections>
+ </customObject>
+ <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
+ <customObject id="-3" userLabel="Application" customClass="NSObject"/>
+ <customObject id="Voe-Tx-rLC" customClass="AppDelegate">
+ <connections>
+ <outlet property="_email_address" destination="geG-ze-MSR" id="d4k-Jk-Tfb"/>
+ <outlet property="_window" destination="QvC-M9-y7g" id="Hng-bF-TGq"/>
+ </connections>
+ </customObject>
+ <customObject id="YLy-65-1bz" customClass="NSFontManager"/>
+ <menu title="Main Menu" systemMenu="main" id="AYu-sK-qS6">
+ <items>
+ <menuItem title="Copy Mailto" id="1Xt-HY-uBw">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Copy Mailto" systemMenu="apple" id="uQy-DD-JDr">
+ <items>
+ <menuItem title="About Copy Mailto" id="5kV-Vb-QxS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="orderFrontStandardAboutPanel:" target="-1" id="Exp-CZ-Vem"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
+ <menuItem title="Services" id="NMo-om-nkz">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <menu key="submenu" title="Services" systemMenu="services" id="hz9-B4-Xy5"/>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="4je-JR-u6R"/>
+ <menuItem title="Hide Copy Mailto" keyEquivalent="h" id="Olw-nP-bQN">
+ <connections>
+ <action selector="hide:" target="-1" id="PnN-Uc-m68"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Hide Others" keyEquivalent="h" id="Vdr-fp-XzO">
+ <modifierMask key="keyEquivalentModifierMask" option="YES" command="YES"/>
+ <connections>
+ <action selector="hideOtherApplications:" target="-1" id="VT4-aY-XCT"/>
+ </connections>
+ </menuItem>
+ <menuItem title="Show All" id="Kd2-mp-pUS">
+ <modifierMask key="keyEquivalentModifierMask"/>
+ <connections>
+ <action selector="unhideAllApplications:" target="-1" id="Dhg-Le-xox"/>
+ </connections>
+ </menuItem>
+ <menuItem isSeparatorItem="YES" id="kCx-OE-vgT"/>
+ <menuItem title="Quit Copy Mailto" keyEquivalent="q" id="4sb-4s-VLi">
+ <connections>
+ <action selector="terminate:" target="-1" id="Te7-pn-YzF"/>
+ </connections>
+ </menuItem>
+ </items>
+ </menu>
+ </menuItem>
+ </items>
+ </menu>
+ <window title="Copy Mailto" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" showsToolbarButton="NO" animationBehavior="default" id="QvC-M9-y7g">
+ <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
+ <windowPositionMask key="initialPositionMask" topStrut="YES" bottomStrut="YES"/>
+ <rect key="contentRect" x="601" y="496" width="480" height="121"/>
+ <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
+ <view key="contentView" wantsLayer="YES" misplaced="YES" id="EiT-Mj-1SZ">
+ <rect key="frame" x="0.0" y="0.0" width="480" height="121"/>
+ <autoresizingMask key="autoresizingMask"/>
+ <subviews>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" id="geG-ze-MSR">
+ <rect key="frame" x="18" y="57" width="444" height="19"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" sendsActionOnEndEditing="YES" title="Email address" id="bWd-ek-Y6D">
+ <font key="font" metaFont="system" size="15"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" misplaced="YES" id="ifM-I2-w4c">
+ <rect key="frame" x="18" y="84" width="221" height="17"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
+ <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Copy email address to clipboard?" id="fXp-NT-DzM">
+ <font key="font" metaFont="systemBold"/>
+ <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
+ </textFieldCell>
+ </textField>
+ <button verticalHuggingPriority="750" misplaced="YES" id="kh0-Tv-Cj9">
+ <rect key="frame" x="394" y="13" width="72" height="32"/>
+ <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
+ <buttonCell key="cell" type="push" title="Copy" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="ujL-03-vyZ">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ <string key="keyEquivalent" base64-UTF8="YES">
+DQ
+</string>
+ </buttonCell>
+ <connections>
+ <action selector="copyEmailToClipboard:" target="Voe-Tx-rLC" id="uX1-7A-IwJ"/>
+ </connections>
+ </button>
+ <button verticalHuggingPriority="750" misplaced="YES" id="dF9-KQ-ymU" customClass="QuitButton">
+ <rect key="frame" x="328" y="13" width="66" height="32"/>
+ <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
+ <buttonCell key="cell" type="push" title="Quit" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="aJz-qw-lxS">
+ <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
+ <font key="font" metaFont="system"/>
+ </buttonCell>
+ <connections>
+ <action selector="terminate:" target="-2" id="ChX-uc-Yql"/>
+ </connections>
+ </button>
+ </subviews>
+ </view>
+ <point key="canvasLocation" x="132" y="42.5"/>
+ </window>
+ </objects>
+</document>
diff --git a/Copy Mailto/CopyMailto.entitlements b/Copy Mailto/CopyMailto.entitlements
new file mode 100644
index 0000000..0c67376
--- /dev/null
+++ b/Copy Mailto/CopyMailto.entitlements
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict/>
+</plist>
diff --git a/Copy Mailto/DefaultURLHandler.h b/Copy Mailto/DefaultURLHandler.h
new file mode 100644
index 0000000..dc09ffc
--- /dev/null
+++ b/Copy Mailto/DefaultURLHandler.h
@@ -0,0 +1,15 @@
+//
+// DefaultURLHandler.h
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface DefaultURLHandler : NSObject
+
++ (OSStatus)setDefaultURLHandler;
+
+@end
diff --git a/Copy Mailto/DefaultURLHandler.m b/Copy Mailto/DefaultURLHandler.m
new file mode 100644
index 0000000..424a0ee
--- /dev/null
+++ b/Copy Mailto/DefaultURLHandler.m
@@ -0,0 +1,24 @@
+//
+// DefaultURLHandler.m
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import "DefaultURLHandler.h"
+
+@implementation DefaultURLHandler
+
++ (OSStatus)setDefaultURLHandler {
+ CFStringRef scheme = (CFStringRef)@"mailto";
+ CFStringRef bundle_identifier = (__bridge CFStringRef)[[NSBundle mainBundle] bundleIdentifier];
+
+ OSStatus status = LSSetDefaultHandlerForURLScheme(scheme, bundle_identifier);
+
+ CFRelease(scheme);
+
+ return status;
+}
+
+@end
diff --git a/Copy Mailto/Info.plist b/Copy Mailto/Info.plist
new file mode 100644
index 0000000..9e3f4b1
--- /dev/null
+++ b/Copy Mailto/Info.plist
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
+ <key>CFBundleExecutable</key>
+ <string>$(EXECUTABLE_NAME)</string>
+ <key>CFBundleIconFile</key>
+ <string></string>
+ <key>CFBundleIdentifier</key>
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>$(PRODUCT_NAME)</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleVersion</key>
+ <string>1</string>
+ <key>LSMinimumSystemVersion</key>
+ <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
+ <key>NSHumanReadableCopyright</key>
+ <string>Copyright © 2018 tw. All rights reserved.</string>
+ <key>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+ <key>CFBundleURLTypes</key>
+ <array>
+ <dict>
+ <key>CFBundleURLName</key>
+ <string>com.teddywing.CopyMailto</string>
+ <key>CFBundleURLSchemes</key>
+ <array>
+ <string>mailto</string>
+ </array>
+ </dict>
+ </array>
+</dict>
+</plist>
diff --git a/Copy Mailto/QuitButton.h b/Copy Mailto/QuitButton.h
new file mode 100644
index 0000000..73c2e9d
--- /dev/null
+++ b/Copy Mailto/QuitButton.h
@@ -0,0 +1,16 @@
+//
+// QuitButton.h
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+#import <Carbon/Carbon.h>
+
+@interface QuitButton : NSButton
+
+- (void)keyDown:(NSEvent *)theEvent;
+
+@end
diff --git a/Copy Mailto/QuitButton.m b/Copy Mailto/QuitButton.m
new file mode 100644
index 0000000..8b8bb52
--- /dev/null
+++ b/Copy Mailto/QuitButton.m
@@ -0,0 +1,22 @@
+//
+// QuitButton.m
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import "QuitButton.h"
+
+@implementation QuitButton
+
+// Quit the application on "q" or "Escape"
+- (void)keyDown:(NSEvent *)theEvent
+{
+ if ([[theEvent characters] isEqualToString:@"q"] ||
+ [theEvent keyCode] == kVK_Escape) {
+ [NSApp terminate:self];
+ }
+}
+
+@end
diff --git a/Copy Mailto/main.m b/Copy Mailto/main.m
new file mode 100644
index 0000000..e61f04e
--- /dev/null
+++ b/Copy Mailto/main.m
@@ -0,0 +1,19 @@
+//
+// main.m
+// CopyMailto
+//
+// Created by tw on 9/5/18.
+// Copyright © 2018 tw. All rights reserved.
+//
+
+#import <Cocoa/Cocoa.h>
+
+#import "DefaultURLHandler.h"
+
+int main(int argc, const char * argv[]) {
+ if (argc == 2 && strcmp(argv[1], "--set-url-handler") == 0) {
+ return [DefaultURLHandler setDefaultURLHandler];
+ }
+
+ return NSApplicationMain(argc, argv);
+}