Cocoa library code
##OSX/KGAppExperation.h
###@interface KGAppExperation : NSObject
Here's an example of how to block and quit an application that has expired:
- (void)applicationWillFinishLaunching:(NSNotification *)notification{
NSInteger daysLeft = [KGAppExperation daysLeftUntilExpiration:14 withCompileTimeZone:[NSTimeZone timeZoneWithName:@"PST"]];
NSLog(@"days left: %lu", daysLeft);
if(daysLeft == 0){
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
NSString *appVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSLog(@"%@ %@ has expired", appName, appVersion);
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:[NSString stringWithFormat:@"%@ has expired", appName]];
[alert setInformativeText:[NSString stringWithFormat:@"The beta period for version %@ has expired.", appVersion]];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
[NSApp terminate:self];
}
}
Days left = compile day - current day <= expiration
The time zone should be set to the time zone the code was compiled in
+ (NSUInteger)daysLeftUntilExpiration:(NSUInteger)days withCompileTimeZone:(NSTimeZone *)timeZone;
##OSX/KGDivider.h
###@interface KGDivider : NSSplitView
###@interface KGDividerDelegate : NSObject
##OSX/KGGrowl.h
###@interface KGGrowl : NSObject
@property (strong, readonly) NSString *notification;
- (id)initWithNotification:(NSString *)newNotification;
- (void)displayMessage:(NSString *)message withTitle:(NSString *)title;
##OSX/KGLogin.h
###@interface KGLogin : NSObject
+ (NSURL *)appURL;
+ (BOOL)willStartAtLogin;
+ (BOOL)willStartAtLogin:(NSURL *)itemURL;
+ (void)setStartAtLogin:(BOOL)enabled;
+ (void)setStartAtLogin:(NSURL *)itemURL enabled:(BOOL)enabled;
##OSX/KGMenuBarPopup.h
###@interface KGMenuBarPopup : NSObject
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSImage *image;
@property (nonatomic, strong) NSImage *alternateImage;
@property (nonatomic) CGFloat width;
- (id)initWithWidth:(CGFloat)width view:(NSView *)view;
- (id)initWithWidth:(CGFloat)width view:(NSView *)view offset:(CGFloat)offset;
- (void)hideView;
- (void)centerView;
##OSX/KGPasteboard.h
###@interface KGPasteboard : NSObject
The general use pasteboard
+ (NSString *)generalPasteBoardString;
Copy a strig to the general pasteboard
+ (void)copyString:(NSString *)string;
Copy a string to the general pasteboard and html to the general html pasteboard
+ (void)copyString:(NSString *)string andHTML:(NSString *)html;
##OSX/KGPopUpButtonImageCell.h
###@interface KGPopUpButtonImageCell : NSPopUpButtonCell
##OSX/KGProcess.h
###@interface KGProcess : NSObject
Transform the process into a forground application
+ (void)transformToForegroundApplication;
Set the application as the front most one
+ (void)setApplicationFront;
##OSX/KGRatingView.h
###@interface KGRatingView : NSView
@property (nonatomic, getter=isEnabled) BOOL enabled;
@property (nonatomic) BOOL allowHalfRating;
@property (nonatomic) NSUInteger rating;
@property (nonatomic) NSTimeInterval hoverDelay;
- (void)setRatingChangedCallback:(KGRatingViewCallback)block;
##OSX/KGURLHandler.h
###@interface KGURLHandler : NSObject
+ (id)handlerWithScheme:(NSString *)scheme andIdentifier:(NSString *)identifier;
- (id)initWithScheme:(NSString *)scheme andIdentifier:(NSString *)identifier;
- (void)registerDefaultAction:(KGURLHandlerAction)action;
- (void)registerCommandPath:(NSString *)path withAction:(KGURLHandlerAction)action;
##OSX/ScriptingBridge/KGFinder.h
###@interface KGFinder : NSObject {}
+ (FinderApplication *)finder;
+ (NSString *)activeFinderWindowURL;
+ (NSArray *)selectedFinderURLs;
##OSX/ScriptingBridge/KGTerminal.h
###@interface KGTerminal : NSObject
+ (NSString *)appId;
+ (TerminalApplication *)terminal;
+ (NSString *)escapePath:(NSString*)path;
+ (void)shellTo:(NSString *)path;
+ (void)shellTo:(NSString *)path clear:(BOOL)clear additionalCommand:(NSString *)additionalCommand;
+ (void)runCommand:(NSString *)command;
##Shared/KGFoundation.h
##Shared/KGImageCache.h
###@interface KGImageCache : NSObject
- (id)initWithCapacity:(NSUInteger)capacity;
- (void)retainKey:(id)key;
- (BOOL)didLoad:(id)key;
- (void)setDidLoad:(id)key;
- (KGImageCacheImage *)imageForKey:(id)key;
- (void)setImage:(KGImageCacheImage *)image forKey:(id)key;
- (void)releaseKey:(id)key;
- (void)removeKey:(id)key;
##Shared/KGKeychain.h
###@interface KGKeychain : NSObject
+ (BOOL)passwordExistsForService:(NSString *)serviceName andAccount:(NSString *)accountName;
+ (BOOL)setPassword:(NSString *)password forService:(NSString *)serviceName andAccount:(NSString *)accountName;
+ (NSString *)passwordForService:(NSString *)serviceName andAccount:(NSString *)accountName;
+ (BOOL)removeEntryForService:(NSString *)serviceName andAccount:(NSString *)accountName;
##Shared/KGXPath.h
##Shared/NSArray+KG.h
###@interface NSArray(KG)
Return the first object in the array
- (id)firstObject;
Return the first n
objects in the array
- (NSArray *)firstObjects:(NSUInteger)count;
Return the last n
objects in the array
- (NSArray *)lastObjects:(NSUInteger)count;
##Shared/NSDictionary+KGJSON.h
###@interface NSDictionary(KGJSON)
- (NSUInteger)uintSafelyFromKey:(id)key;
- (NSString *)stringSafelyFromKey:(id)key;
- (NSURL *)URLSafelyFromKey:(id)key;
- (id)objectSafelyFromKey:(id)key;
##Shared/NSMutableAttributedString+KG.h
###@interface NSMutableAttributedString(KG)
- (NSRange)replaceString:(NSString *)src withString:(NSString *)dst;
- (void)replaceString:(NSString *)src withString:(NSString *)dst andAttributes:(NSDictionary *)attributes;
- (void)replaceString:(NSString *)src withString:(NSString *)dst andLink:(NSURL *)url withTooltip:(NSString *)tooltip;
- (void)addTextShadow:(NSShadow *)shadow;
##Shared/NSString+KGFile.h
###@interface NSString(KGFile)
Return a valid filename
- (NSString *)validFilename;
Return a valid filename, if allowHidden
is YES
then periods will be allows as the first character
- (NSString *)validFilenameAllowHidden:(BOOL)allowHidden;
Transform a path into it's true mount path, or return nil
Example: /Volumes/slave1
-> afp://Slave%20One/slave1
- (NSString *)volumeMountURLWithError:(NSError **)error;
##Shared/NSString+KGHTTP.h
###@interface NSString(KGHTTP)
Encode a dictionary into a url string.
Example: {name:'David Keegan', age:26}
-> name=David%20Keegan&age=26
+ (NSString *)urlEncodedStringForArgs:(NSDictionary *)args;
URL encode a string, this encodes more characters than [NSString stringByAddingPercentEscapesUsingEncoding:]
- (NSString *)stringWithURLEncoding;