cocoa

add customView to NSStatusItem

馋奶兔 提交于 2021-02-07 09:46:44
问题 I would like to create a status bar application which has non-menu style. same as FaceTab for facebook (I mean only interface, not functional)... this is my codes: -(void)awakeFromNib{ statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; [statusItem setView:customView]; //[statusItem setMenu:menu]; [statusItem setTitle:@"Status"]; [statusItem setHighlightMode:YES]; } ..... so once I Use NSMenu everything works fine but when I use NSView and

add customView to NSStatusItem

一世执手 提交于 2021-02-07 09:43:03
问题 I would like to create a status bar application which has non-menu style. same as FaceTab for facebook (I mean only interface, not functional)... this is my codes: -(void)awakeFromNib{ statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain]; [statusItem setView:customView]; //[statusItem setMenu:menu]; [statusItem setTitle:@"Status"]; [statusItem setHighlightMode:YES]; } ..... so once I Use NSMenu everything works fine but when I use NSView and

macOS swift - save data to local storage - best practices

女生的网名这么多〃 提交于 2021-02-07 09:11:01
问题 I'm a newbie in macOS development. I have an application where I need to save a string (for example a token) to some local storage, and after closing and opening app I want to retrieve this string back. Is it somehow possible that only my app would be able to retrieve this string? Is it better to write it to the txt file or there are some other possibilities? Thank you. 回答1: It depends on the security of the data. If security matters save the string in the keychain. If security does not

Auto-Resizing of NSTextView and/or NSScrollView

南笙酒味 提交于 2021-02-07 08:23:00
问题 I have an NSTextView inside an NSView (which is being used by a NSPopover , don't know if that is relevant) that I'm trying to resize automatically and programmatically (cf caption). I have been struggling with a lot of stuff, namely : Looking at NSLayoutManager and usedRectForTextContainer that give me aberrant size values ( usedRectForTextContainer : {{0, 0}, {0.001, 28}} ) Modifying NSScrollView frame , [NSScrollView contentView] , [NSScrollView documentView] Getting rid of AutoLayout I

Auto-Resizing of NSTextView and/or NSScrollView

*爱你&永不变心* 提交于 2021-02-07 08:21:30
问题 I have an NSTextView inside an NSView (which is being used by a NSPopover , don't know if that is relevant) that I'm trying to resize automatically and programmatically (cf caption). I have been struggling with a lot of stuff, namely : Looking at NSLayoutManager and usedRectForTextContainer that give me aberrant size values ( usedRectForTextContainer : {{0, 0}, {0.001, 28}} ) Modifying NSScrollView frame , [NSScrollView contentView] , [NSScrollView documentView] Getting rid of AutoLayout I

Open a terminal window to a specified folder from a Cocoa app

≯℡__Kan透↙ 提交于 2021-02-07 05:51:40
问题 I have seen this thread on how to execute terminal commands from within a Cocoa app. But I want to actually launch Terminal.app to a specified directory. I know that the following does not work: [[NSWorkspace sharedWorkspace] openFile:folderPath withApplication:@"Terminal"]; Terminal tries to actually open the folder as a file. Is this something I have to use AppleScript for? Any ideas? 回答1: You could use AppleScript from Cocoa like this: NSString *s = [NSString stringWithFormat: @"tell

How to efficiently read thousands of small files with GCD

£可爱£侵袭症+ 提交于 2021-02-07 05:41:26
问题 I'd like to read some metadata data (e.x.: EXIF data) from potentially thousands of files as efficiently as possible without impacting the user experience. I'm interested if anyone has any thoughts on how best to go about this using something like regular GCD queues, dispatch_io channels or even another implementation. Option #1: Using regular GCD queues. This one is pretty straightforward I can just use something like the following: for (NSURL *URL in URLS) { dispatch_async(dispatch_get

Hanging NSTask using waitUntilExit

依然范特西╮ 提交于 2021-02-07 05:34:18
问题 I need to use NSTask synchronously, however I find that occasionally my task hangs under the 'waitUntilExit' command. I wonder if there is a graceful way--an error handling method--to terminated the hanging task so I can re-launch another? 回答1: Note that if the task being run via NSTask fills the output pipe then the process will hang, effectively blocking waitUntilExit from returning. You can prevent this situation by calling [task.standardOutput.fileHandleForReading readDataToEndOfFile];

Changing size of NSTextView

泄露秘密 提交于 2021-02-07 04:01:18
问题 I am trying to implement an NSTextView which resizes to fit its content. I am trying to make it so it has a maximum amount of lines. Meaning, that when this limit is reached, it will not grow any further and the user will be able to scroll it. There seem to be a lot of people wanting this but I have not found a complete implementation of this. The idea is to take the content size of the NSTextView and resize it so that it matches. I just can't figure out how to set the layout size of the

Changing size of NSTextView

蹲街弑〆低调 提交于 2021-02-07 04:00:08
问题 I am trying to implement an NSTextView which resizes to fit its content. I am trying to make it so it has a maximum amount of lines. Meaning, that when this limit is reached, it will not grow any further and the user will be able to scroll it. There seem to be a lot of people wanting this but I have not found a complete implementation of this. The idea is to take the content size of the NSTextView and resize it so that it matches. I just can't figure out how to set the layout size of the