Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 10 commits
  • 6 files changed
  • 0 commit comments
  • 3 contributors
View
7 LICENSE
@@ -0,0 +1,7 @@
+Copyright (c) 2014 David Keegan (http://davidkeegan.com)
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
7 LLManager.h
@@ -8,11 +8,18 @@
#import <Foundation/Foundation.h>
+
+extern NSString * const LLManagerSetLaunchAtLoginFailedNotification;
+
+
@interface LLManager : NSObject
+ (BOOL)launchAtLogin;
+ (void)setLaunchAtLogin:(BOOL)value;
++ (void)setLaunchAtLogin:(BOOL)value
+ notifyOnFailure:(BOOL)wantFailureNotification;
@property (assign) BOOL launchAtLogin;
+@property (assign) BOOL notifyIfSetLaunchAtLoginFailed;
@end
View
35 LLManager.m
@@ -10,17 +10,22 @@
#import "LLStrings.h"
#import <ServiceManagement/ServiceManagement.h>
+
+NSString * const LLManagerSetLaunchAtLoginFailedNotification = @"LLManagerSetLaunchAtLoginFailedNotification";
+
+
@implementation LLManager
+ (BOOL)launchAtLogin{
BOOL launch = NO;
CFArrayRef cfJobs = SMCopyAllJobDictionaries(kSMDomainUserLaunchd);
+ if(cfJobs == NULL) return NO;
#if __has_feature(objc_arc)
- NSArray *jobs = [NSArray arrayWithArray:(__bridge NSArray *)cfJobs];
+ NSArray *jobs = CFBridgingRelease(cfJobs);
#else
NSArray *jobs = [NSArray arrayWithArray:(NSArray *)cfJobs];
-#endif
CFRelease(cfJobs);
+#endif
if([jobs count]){
for(NSDictionary *job in jobs){
if([job[@"Label"] isEqualToString:LLHelperBundleIdentifier]){
@@ -32,9 +37,26 @@ + (BOOL)launchAtLogin{
return launch;
}
-+ (void)setLaunchAtLogin:(BOOL)value{
- if(!SMLoginItemSetEnabled((CFStringRef)LLHelperBundleIdentifier, value)){
- NSLog(@"SMLoginItemSetEnabled failed!");
++ (void)setLaunchAtLogin:(BOOL)value {
+ [self setLaunchAtLogin:value
+ notifyOnFailure:NO];
+}
+
++ (void)setLaunchAtLogin:(BOOL)value
+ notifyOnFailure:(BOOL)wantFailureNotification {
+#if __has_feature(objc_arc)
+ CFStringRef LLHelperBundleIdentifierCF = (__bridge CFStringRef)LLHelperBundleIdentifier;
+#else
+ CFStringRef LLHelperBundleIdentifierCF = (CFStringRef)LLHelperBundleIdentifier;
+#endif
+
+ if(!SMLoginItemSetEnabled(LLHelperBundleIdentifierCF, value)){
+ if(wantFailureNotification){
+ [[NSNotificationCenter defaultCenter] postNotificationName:LLManagerSetLaunchAtLoginFailedNotification object:self];
+ }
+ else {
+ NSLog(@"SMLoginItemSetEnabled failed!");
+ }
}
}
@@ -46,7 +68,8 @@ - (BOOL)launchAtLogin {
- (void)setLaunchAtLogin:(BOOL)launchAtLogin {
[self willChangeValueForKey:@"launchAtLogin"];
- [[self class] setLaunchAtLogin:launchAtLogin];
+ [[self class] setLaunchAtLogin:launchAtLogin
+ notifyOnFailure:self.notifyIfSetLaunchAtLoginFailed];
[self didChangeValueForKey:@"launchAtLogin"];
}
View
1  LaunchAtLoginHelper.xcodeproj/project.pbxproj
@@ -51,6 +51,7 @@
734C379515414CE200994189 /* Products */,
);
sourceTree = "<group>";
+ usesTabs = 0;
};
734C379515414CE200994189 /* Products */ = {
isa = PBXGroup;
View
23 LaunchAtLoginSample/LaunchAtLoginSample.xcodeproj/project.pbxproj
@@ -89,6 +89,7 @@
734C37591541467600994189 /* Products */,
);
sourceTree = "<group>";
+ usesTabs = 0;
};
734C37591541467600994189 /* Products */ = {
isa = PBXGroup;
@@ -158,7 +159,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = LL;
- LastUpgradeCheck = 0430;
+ LastUpgradeCheck = 0500;
ORGANIZATIONNAME = "David Keegan";
};
buildConfigurationList = 734C37521541467600994189 /* Build configuration list for PBXProject "LaunchAtLoginSample" */;
@@ -231,7 +232,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
@@ -245,7 +251,9 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
ONLY_ACTIVE_ARCH = YES;
@@ -257,7 +265,12 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
- ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_WARN_BOOL_CONVERSION = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -265,7 +278,9 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 10.7;
SDKROOT = macosx;
@@ -277,6 +292,7 @@
buildSettings = {
CODE_SIGN_ENTITLEMENTS = LaunchAtLoginSample.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
+ COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = "LaunchAtLoginSample-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -289,6 +305,7 @@
buildSettings = {
CODE_SIGN_ENTITLEMENTS = LaunchAtLoginSample.entitlements;
CODE_SIGN_IDENTITY = "Mac Developer";
+ COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = "LaunchAtLoginSample-Info.plist";
PRODUCT_NAME = "$(TARGET_NAME)";
View
7 readme.md
@@ -26,6 +26,13 @@ $ cd LaunchAtLoginHelper
$ python setup.py <main_app_url_scheme> <helper_app_bundle_identifier>
```
+For the sample code the above will look like this:
+
+```
+$ cd LaunchAtLoginHelper
+$ python setup.py launchatloginsample com.InScopeApps.ShellTo.LaunchAtLoginHelper
+```
+
This will create `LLStrings.h` which is used in both the helper app and the main app and contains `#define`'s for the url scheme and the helper app's bundle identifier. `LaunchAtLoginHelper-Info.plist` is also created for the helper app with it's custom bundle identifier filled in.
Once these two files are generated it's time to add **LaunchAtLoginHelper** to the main app. Drag `LaunchAtLoginHelper.xcodeproj`, `LLStrings.h`, `LLManager.h`, and `LLManager.m` to the main app's project.

No commit comments for this range

Something went wrong with that request. Please try again.