forked from audetto/AppleWin
-
Notifications
You must be signed in to change notification settings - Fork 6
Lessons Learned
sh95014 edited this page Feb 17, 2022
·
13 revisions
NSLog(@"%s", __PRETTY_FUNCTION__);
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"..."]
[string enumerateSubstringsInRange:NSMakeRange(0, string.length)
options:NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
// filter out multi-byte characters
if (substringRange.length == 1) {
[NSRunningApplication currentApplication].localizedName
[[NSSound soundNamed:@"Blow"] play];
clock_gettime_nsec_np(CLOCK_UPTIME_RAW)
Here's a good step-by-step tutorial, and here is where I finally got search to work.
Apparently helpd
only observes a few directories to update its index, and Xcode build output directories aren't included. Copy the binary to /Applications
.
[NSImage imageWithSystemSymbolName:@"..." accessibilityDescription:@""]
NSImage *image = [[NSImage alloc] initWithData:[NSData dataWithBytes:buffer length:bufferSize]];
CGImageRef cgRef = [image CGImageForProposedRect:NULL context:nil hints:nil];
NSBitmapImageRep *newRep = [[NSBitmapImageRep alloc] initWithCGImage:cgRef];
[newRep setSize:[image size]];
NSData *pngData = [newRep representationUsingType:NSBitmapImageFileTypePNG properties:@{}];
NSError *error;
NSView *templateView;
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:templateView requiringSecureCoding:NO error:&error];
...
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingFromData:archive error:&error];
unarchiver.requiresSecureCoding = NO;
NSView *duplicateView = [unarchiver decodeObjectForKey:NSKeyedArchiveRootObjectKey];
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
- (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url;
Use NSMenuItem
's representedObject
- (void)viewDidLoad {
...
self.preferredContentSize = self.view.frame.size;
- (BOOL)windowShouldClose:(NSWindow *)sender {
[self.window orderOut:sender];
return NO;
}
[[NSBundle mainBundle] loadNibNamed:@"About" owner:self topLevelObjects:nil]
NSStoryboard *storyboard = [NSStoryboard storyboardWithName:@"..." bundle:nil];
UIViewController controller = [storyboard instantiateInitialController];
[controller showWindow:sender];
NSMenu *editMenu = [[[[NSApplication sharedApplication] mainMenu] itemWithTag:EDIT_TAG] submenu];
for (NSMenuItem *item in [editMenu itemArray]) {
if ([item action] == NSSelectorFromString(@"startDictation:") ||
[item action] == NSSelectorFromString(@"orderFrontCharacterPalette:")) {
[editMenu removeItem:item];
}
}
// make sure a separator is not the bottom option
const NSInteger lastItemIndex = [editMenu numberOfItems] - 1;
if ([[editMenu itemAtIndex:lastItemIndex] isSeparatorItem]) {
[editMenu removeItemAtIndex:lastItemIndex];
}
- (IBAction)copy:(id)sender {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:@[ NSPasteboardTypePNG ] owner:nil];
if ([pasteboard setData:pngData forType:NSPasteboardTypePNG]) {
- (IBAction)paste:(id)sender {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSString *string = [pasteboard stringForType:NSPasteboardTypeString];
- (void)flagsChanged:(NSEvent*)event {
if (event.keyCode == kVK_CapsLock) {
- (void)keyDown:(NSEvent *)event {
if (event.modifierFlags & NSEventModifierFlagControl) {
- (void)keyDown:(NSEvent *)event {
event.charactersIgnoringModifiers
self.trackingRectTag = [self addTrackingRect:self.bounds owner:self userData:NULL assumeInside:YES];
...
- (void)mouseEntered:(NSEvent *)event {
...
}
- (void)mouseExited:(NSEvent *)event {
...
}
[self removeTrackingRect:self.trackingRectTag];
self.trackingRectTag = [self addTrackingRect:self.bounds owner:self userData:NULL assumeInside:YES];
- (void)mouseDown:(NSEvent *)event;
- (void)mouseUp:(NSEvent *)event;
- (void)rightMouseDown:(NSEvent *)event;
- (void)rightMouseUp:(NSEvent *)event;
- (void)mouseMoved:(NSEvent *)event;
- (void)mouseDragged:(NSEvent *)event; // needed for mouseMoved + mouseDown
NSNumber *isDirectory;
([url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:nil] && [isDirectory boolValue])
NSNumber *isPackage;
([url getResourceValue:&isPackage forKey:NSURLIsPackageKey error:nil] && [isPackage boolValue])
NSURL *folder = ...;
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtURL:folder
includingPropertiesForKeys:nil
options:(NSDirectoryEnumerationSkipsPackageDescendants | NSDirectoryEnumerationSkipsHiddenFiles)
errorHandler:^(NSURL *url, NSError *error) { return YES; }];
for (NSURL *url in enumerator) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
NSString *bundleId = [[NSBundle mainBundle] bundleIdentifier];
NSString *supportDirectoryPath = [NSString stringWithFormat:@"%@/%@/", paths.firstObject, bundleId];
NSURL *url = [NSURL fileURLWithPath:supportDirectoryPath isDirectory:YES];
NSError *error;
[[NSFileManager defaultManager] createDirectoryAtURL:url withIntermediateDirectories:YES attributes:nil error:&error];
Use NSString
's stringByAbbreviatingWithTildeInPath
https://github.com/Flinesoft/BartyCrouch
Find the symbol you want in the SF Symbols app and select it, then Edit > Copy Image As... to copy the SVG into the pasteboard. Paste into a text editor and save as a .svg file. It can then be used in HTML as
<img src="icon.svg" />
Use https://codepen.io/sosuke/pen/Pjoqqp to generate the filter and set it in CSS.