Skip to content

Commit

Permalink
Implemented feature request at #7
Browse files Browse the repository at this point in the history
Application now supports basic AppleScript commands:
* KeyOn
*KeyOff

see changes to README.md for example usage.
  • Loading branch information
pallotron committed Feb 24, 2014
1 parent 25bfe22 commit cabf53b
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 27 deletions.
23 changes: 23 additions & 0 deletions README.md
Expand Up @@ -40,6 +40,24 @@ Download
Download the latest version in DMG format from
[github release page here](https://github.com/pallotron/yubiswitch/releases/).

Integration with shell
======================

The application supports two basic AppleScript commands:

* KeyOn
* KeyOff

You can switch your yubikey on and off using this basic osacript commands:

```
$ osascript -e 'tell application "yubiswitch" to KeyOn'
```

```
$ osascript -e 'tell application "yubiswitch" to KeyOff'
```

Screenshots
===========

Expand Down Expand Up @@ -74,9 +92,14 @@ YubiKey) when user preferences are changed

- [x] Add "Start at login" feature

- [x] Support for basic AppleScript comomands: KeyOn/KeyOff

- [ ] Feature: lock computer when yubikey is removed (use
IOServiceAddMatchingNotification in IOKit?)

- [ ] Feature: check update features, check if current version is the latest.
Connect to github somehow

- [ ] Support more yubikeys nano on multiple USB slots

- [ ] Better support for plug and unplug events
Expand Down
13 changes: 13 additions & 0 deletions YubiSwitch.sdef
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd">
<dictionary title="YubiSwitch Terminology">
<suite name="YubiSwitch Suite" code="Yubi"
description="YubiSwitch app scripting support">
<command name="KeyOn" code="yubicmOn" description="Enables yubikey">
<cocoa class="YubiKeyScript"/>
</command>
<command name="KeyOff" code="yubicOff" description="Disables yubikey">
<cocoa class="YubiKeyScript"/>
</command>
</suite>
</dictionary>
34 changes: 34 additions & 0 deletions yubiswitch.xcodeproj/project.pbxproj
Expand Up @@ -19,6 +19,8 @@
593B4E0E17F0A2BD003195DE /* PreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 593B4E0C17F0A2BD003195DE /* PreferencesController.m */; };
593B4E0F17F0A2BD003195DE /* PreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 593B4E0D17F0A2BD003195DE /* PreferencesController.xib */; };
594DCCE717EF99D400D9C2E2 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 594DCCE617EF99D400D9C2E2 /* LICENSE */; };
5983505918BA3B19001917C7 /* YubiSwitch.sdef in Resources */ = {isa = PBXBuildFile; fileRef = 5983505818BA3B19001917C7 /* YubiSwitch.sdef */; };
59882B5D18BA7735001B9389 /* YubiKeyScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 59882B5C18BA7735001B9389 /* YubiKeyScript.m */; };
598AF34517F380C4008165C6 /* DefaultPreferences.plist in Resources */ = {isa = PBXBuildFile; fileRef = 598AF34417F380C4008165C6 /* DefaultPreferences.plist */; };
59C0616D17EED74400D3EE79 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59E5CF0E17EC2A9000898135 /* Cocoa.framework */; };
59E5CF1917EC2A9000898135 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 59E5CF1717EC2A9000898135 /* InfoPlist.strings */; };
Expand All @@ -28,6 +30,9 @@
59E5CF4417EC472400898135 /* YubiKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 59E5CF4317EC472400898135 /* YubiKey.m */; };
59EC128A17ECFAFD00B3C3A6 /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 59EC128917ECFAFD00B3C3A6 /* README.md */; };
59EC128C17ECFEFE00B3C3A6 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 59EC128B17ECFEFE00B3C3A6 /* IOKit.framework */; };
59EECB3C180440950091AF5E /* screenshot-prefs.png in Resources */ = {isa = PBXBuildFile; fileRef = 59EECB3A180440950091AF5E /* screenshot-prefs.png */; };
59EECB3D180440950091AF5E /* screenshot-menuitems.png in Resources */ = {isa = PBXBuildFile; fileRef = 59EECB3B180440950091AF5E /* screenshot-menuitems.png */; };
59EECB441804422C0091AF5E /* createdmg.sh in Resources */ = {isa = PBXBuildFile; fileRef = 59EECB431804422C0091AF5E /* createdmg.sh */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -85,6 +90,10 @@
593B4E0C17F0A2BD003195DE /* PreferencesController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PreferencesController.m; sourceTree = "<group>"; };
593B4E0D17F0A2BD003195DE /* PreferencesController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PreferencesController.xib; sourceTree = "<group>"; };
594DCCE617EF99D400D9C2E2 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
5970C8D418B3A48100CDE1BB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
5983505818BA3B19001917C7 /* YubiSwitch.sdef */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = YubiSwitch.sdef; path = ../YubiSwitch.sdef; sourceTree = "<group>"; };
59882B5B18BA7735001B9389 /* YubiKeyScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YubiKeyScript.h; sourceTree = "<group>"; };
59882B5C18BA7735001B9389 /* YubiKeyScript.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YubiKeyScript.m; sourceTree = "<group>"; };
598AF34417F380C4008165C6 /* DefaultPreferences.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = DefaultPreferences.plist; sourceTree = "<group>"; };
59C0616B17EED6AB00D3EE79 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = System/Library/Frameworks/Carbon.framework; sourceTree = SDKROOT; };
59E5CF0B17EC2A9000898135 /* yubiswitch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = yubiswitch.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -105,6 +114,9 @@
59E5CF4317EC472400898135 /* YubiKey.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YubiKey.m; sourceTree = "<group>"; };
59EC128917ECFAFD00B3C3A6 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
59EC128B17ECFEFE00B3C3A6 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
59EECB3A180440950091AF5E /* screenshot-prefs.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "screenshot-prefs.png"; sourceTree = "<group>"; };
59EECB3B180440950091AF5E /* screenshot-menuitems.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "screenshot-menuitems.png"; sourceTree = "<group>"; };
59EECB431804422C0091AF5E /* createdmg.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = createdmg.sh; path = dmg/createdmg.sh; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -135,6 +147,8 @@
59013C9117F6CDB900005A7E /* images */ = {
isa = PBXGroup;
children = (
59EECB3A180440950091AF5E /* screenshot-prefs.png */,
59EECB3B180440950091AF5E /* screenshot-menuitems.png */,
59013C9217F6CDB900005A7E /* nano.jpg */,
);
path = images;
Expand All @@ -146,6 +160,7 @@
59013C7F17F56F0F00005A7E /* ShortcutRecorder.xcodeproj */,
59EC128917ECFAFD00B3C3A6 /* README.md */,
594DCCE617EF99D400D9C2E2 /* LICENSE */,
59EECB42180442230091AF5E /* dmg */,
59E5CF1417EC2A9000898135 /* yubiswitch */,
59E5CF0D17EC2A9000898135 /* Frameworks */,
59E5CF0C17EC2A9000898135 /* Products */,
Expand All @@ -168,6 +183,7 @@
59EC128B17ECFEFE00B3C3A6 /* IOKit.framework */,
59E5CF0E17EC2A9000898135 /* Cocoa.framework */,
59E5CF2D17EC2A9000898135 /* XCTest.framework */,
5970C8D418B3A48100CDE1BB /* Foundation.framework */,
59E5CF1017EC2A9000898135 /* Other Frameworks */,
);
name = Frameworks;
Expand Down Expand Up @@ -196,6 +212,9 @@
59E5CF2017EC2A9000898135 /* AppDelegate.h */,
59E5CF2117EC2A9000898135 /* AppDelegate.m */,
59E5CF2317EC2A9000898135 /* MainMenu.xib */,
59882B5B18BA7735001B9389 /* YubiKeyScript.h */,
59882B5C18BA7735001B9389 /* YubiKeyScript.m */,
5983505818BA3B19001917C7 /* YubiSwitch.sdef */,
59E5CF4217EC472400898135 /* YubiKey.h */,
59E5CF4317EC472400898135 /* YubiKey.m */,
59E5CF2617EC2A9000898135 /* Images.xcassets */,
Expand All @@ -216,6 +235,14 @@
name = "Supporting Files";
sourceTree = "<group>";
};
59EECB42180442230091AF5E /* dmg */ = {
isa = PBXGroup;
children = (
59EECB431804422C0091AF5E /* createdmg.sh */,
);
name = dmg;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -322,10 +349,14 @@
594DCCE717EF99D400D9C2E2 /* LICENSE in Resources */,
598AF34517F380C4008165C6 /* DefaultPreferences.plist in Resources */,
59E5CF1917EC2A9000898135 /* InfoPlist.strings in Resources */,
5983505918BA3B19001917C7 /* YubiSwitch.sdef in Resources */,
593B4E0A17F09362003195DE /* AboutWindowController.xib in Resources */,
59EECB3D180440950091AF5E /* screenshot-menuitems.png in Resources */,
59EECB3C180440950091AF5E /* screenshot-prefs.png in Resources */,
59013C9317F6CDB900005A7E /* nano.jpg in Resources */,
59013C8D17F571CE00005A7E /* MainMenu.xib in Resources */,
59E5CF2717EC2A9000898135 /* Images.xcassets in Resources */,
59EECB441804422C0091AF5E /* createdmg.sh in Resources */,
593B4E0F17F0A2BD003195DE /* PreferencesController.xib in Resources */,
59EC128A17ECFAFD00B3C3A6 /* README.md in Resources */,
);
Expand All @@ -339,6 +370,7 @@
buildActionMask = 2147483647;
files = (
593B4E0E17F0A2BD003195DE /* PreferencesController.m in Sources */,
59882B5D18BA7735001B9389 /* YubiKeyScript.m in Sources */,
59E5CF2217EC2A9000898135 /* AppDelegate.m in Sources */,
593B4E0917F09362003195DE /* AboutWindowController.m in Sources */,
59E5CF4417EC472400898135 /* YubiKey.m in Sources */,
Expand Down Expand Up @@ -458,6 +490,7 @@
GCC_PREFIX_HEADER = "yubiswitch/yubiswitch-Prefix.pch";
INFOPLIST_FILE = "yubiswitch/yubiswitch-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "@executable_path/../Frameworks ";
MACOSX_DEPLOYMENT_TARGET = 10.8;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand All @@ -473,6 +506,7 @@
GCC_PREFIX_HEADER = "yubiswitch/yubiswitch-Prefix.pch";
INFOPLIST_FILE = "yubiswitch/yubiswitch-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "@executable_path/../Frameworks ";
MACOSX_DEPLOYMENT_TARGET = 10.8;
ONLY_ACTIVE_ARCH = NO;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand Down
Expand Up @@ -4,11 +4,21 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>10.7.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>release.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>yubiswitch-service.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>5</integer>
</dict>
<key>yubiswitch.xcscheme</key>
<dict>
<key>orderHint</key>
Expand All @@ -17,6 +27,11 @@
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>5970C8D218B3A48100CDE1BB</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>59E5CF0A17EC2A9000898135</key>
<dict>
<key>primary</key>
Expand Down
6 changes: 3 additions & 3 deletions yubiswitch/AboutWindowController.xib
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4510" systemVersion="12F37" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4514" systemVersion="13B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment defaultVersion="1080" identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4510"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4514"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="AboutWindowController">
Expand Down Expand Up @@ -30,7 +30,7 @@

Enable/Disable Yubikey Nano

Copyright (C) 2013 Angelo "pallotron" Failla &lt;pallotron@freaknet.org>
Copyright (C) 2013 Angelo "pallotron" Failla &lt;pallotron@freaknet.org&gt;

http://github.com/pallotron/yubiswitch</string>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
Expand Down
3 changes: 2 additions & 1 deletion yubiswitch/AppDelegate.h
Expand Up @@ -40,12 +40,13 @@
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSUserDefaultsController *controller;


-(IBAction)toggleSwitchOffDelay:(id)sender;
-(IBAction)toggleLockWhenUnplugged:(id)sender;
-(IBAction)toggle:(id)sender;
-(IBAction)quit:(id)sender;
-(IBAction)about:(id)sender;
-(IBAction)pref:(id)sender;
-(void)enableYubiKey:(BOOL)enable;
-(void)notify:(NSString *)msg;
-(void)reDisableYK;
-(NSTimer*)createTimer:(NSInteger)interval;
Expand Down
56 changes: 39 additions & 17 deletions yubiswitch/AppDelegate.m
Expand Up @@ -104,6 +104,13 @@ -(void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject
action:@selector(toggle:)];
[hotKeyCenter registerHotKey:newHotKey];
}
NSDictionary* hotkey = [[NSUserDefaults standardUserDefaults]
dictionaryForKey:@"hotkey"];
[[statusMenu itemAtIndex:0]
setKeyEquivalent:[hotkey valueForKey:@"charactersIgnoringModifiers"]];
[[statusMenu itemAtIndex:0]
setKeyEquivalentModifierMask:
[[hotkey valueForKey:@"modifierFlags"] unsignedIntValue]];
}
else
[super observeValueForKeyPath:aKeyPath ofObject:anObject change:aChange
Expand Down Expand Up @@ -135,45 +142,60 @@ -(void)reDisableYK {
}
}

-(IBAction)toggle:(id)sender {
-(void)enableYubiKey:(BOOL)enable {
BOOL res;
if (isEnabled == true) {
res = [yk disable];
if (res == TRUE) {
[statusItem setToolTip:(@"YubiKey disabled")];
[statusItem setImage:[NSImage imageNamed:@"ico_disabled"]];
isEnabled = false;
[[statusMenu itemAtIndex:0] setState:0];
[self notify:@"YubiKey disabled"];
}
} else {
if (enable == TRUE) {
res = [yk enable];
if (res == TRUE) {
} else {
res = [yk disable];
}
if (res == TRUE) {
if (enable == TRUE) {
[statusItem setToolTip:(@"YubiKey enabled")];
[statusItem setImage:[NSImage imageNamed:@"ico_enabled"]];
isEnabled = true;
[[statusMenu itemAtIndex:0] setState:1];
[self notify:@"YubiKey enabled"];
NSDictionary* switchOffDelayPrefs =
[[NSUserDefaults standardUserDefaults]
dictionaryForKey:@"switchOffDelay"];
bool enabled = [[switchOffDelayPrefs valueForKey:@"enabled"] boolValue];
[[NSUserDefaults standardUserDefaults]
dictionaryForKey:@"switchOffDelay"];
bool enabled = [[switchOffDelayPrefs valueForKey:@"enabled"]
boolValue];
if (enabled == TRUE) {
NSNumberFormatter* f = [[NSNumberFormatter alloc] init];
[f setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber* interval = [f numberFromString:
[switchOffDelayPrefs
valueForKey:@"interval"]];
reDisableTimer = [self createTimer:(long)[interval integerValue]];
valueForKey:@"interval"]];
reDisableTimer = [self createTimer:(long)[interval
integerValue]];
}
} else {
[statusItem setToolTip:(@"YubiKey disabled")];
[statusItem setImage:[NSImage imageNamed:@"ico_disabled"]];
isEnabled = false;
[[statusMenu itemAtIndex:0] setState:0];
[self notify:@"YubiKey disabled"];
}
}
}

-(IBAction)toggle:(id)sender {
if (isEnabled == TRUE) {
[self enableYubiKey:FALSE];
} else {
[self enableYubiKey:TRUE];
}
}

-(IBAction)toggleSwitchOffDelay:(id)sender {
[controller save:self];
}

-(IBAction)toggleLockWhenUnplugged:(id)sender {
[controller save:self];
}

-(IBAction)about:(id)sender {
[[aboutwc window] makeKeyAndOrderFront:self];
[[aboutwc window] setOrderedIndex:0];
Expand Down
17 changes: 15 additions & 2 deletions yubiswitch/Base.lproj/MainMenu.xib
Expand Up @@ -27,8 +27,18 @@
<action selector="toggle:" target="494" id="LLD-CQ-Jz5"/>
</connections>
</menuItem>
<menuItem title="Unplugging YubiKey locks computer" enabled="NO" id="JMl-Ij-uOI">
<menuItem title="Unplugging YubiKey locks computer" id="JMl-Ij-uOI">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleLockWhenUnplugged:" target="494" id="Qmm-V7-wjt"/>
<binding destination="BET-T9-5EC" name="value" keyPath="values.lockWhenUnplugged" id="4FX-6R-f2F">
<dictionary key="options">
<bool key="NSRaisesForNotApplicableKeys" value="NO"/>
<bool key="NSConditionallySetsEnabled" value="NO"/>
<bool key="NSAllowsEditingMultipleValuesSelection" value="NO"/>
</dictionary>
</binding>
</connections>
</menuItem>
<menuItem title="Automatically switch off YubiKey" toolTip="Automatically switch off the YubiKey after number of seconds specified in preference window." id="bbU-bX-p6O">
<modifierMask key="keyEquivalentModifierMask"/>
Expand All @@ -51,6 +61,9 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="aPh-QD-f9O"/>
<menuItem title="Check for updates" id="XaQ-BT-Dgg">
<modifierMask key="keyEquivalentModifierMask"/>
</menuItem>
<menuItem title="About YubiSwitch" id="5yW-Sr-JES">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
Expand All @@ -66,7 +79,7 @@
</menuItem>
</items>
</menu>
<objectController automaticallyPreparesContent="YES" id="W0R-qr-9Af">
<objectController automaticallyPreparesContent="YES" id="W0R-qr-9Af" userLabel="Object ControllerSwitchOff">
<connections>
<binding destination="BET-T9-5EC" name="editable" keyPath="values.seconds" id="8iY-8h-6pO"/>
<binding destination="BET-T9-5EC" name="contentObject" keyPath="values.switchOffDelay" id="KPu-8m-Lhl">
Expand Down
2 changes: 2 additions & 0 deletions yubiswitch/DefaultPreferences.plist
Expand Up @@ -2,6 +2,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>lockWhenUnplugged</key>
<true/>
<key>hotKeyProductID</key>
<string>0x0010</string>
<key>hotKeyVendorID</key>
Expand Down

0 comments on commit cabf53b

Please sign in to comment.