nsstatusitem

Is it possible to add a NSStatusItem to a specific position in NSStatusBar?

↘锁芯ラ 提交于 2019-12-01 03:19:01
问题 I use self.statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; to add an statusItem to the systemStatusBar on OSX. The statusItem then appears on the left-most position in the systemStatusBar. I was wondering if there is a way to add such an item to a specific index e.g. on the left side of the system clock? 回答1: Yes and no. Using private API you can specify priority for adding NSStatusItem . I have developed a tiny category for NSStatusBar

NSStatusBarButton keep highlighted

江枫思渺然 提交于 2019-11-29 03:54:00
As of OS X 10.10 most of NSStatusItem has been deprecated in favour of the button property, which consists of an NSStatusBarButton. It should work like a normal button but unfortunately the cell and setCell methods in NSStatusButton have also been deprecated. As a result of this I'm struggling to find a way to keep the button highlighted after it's clicked (Normally the button is highlighted on mouse down, and unhighlighted on mouse up. I want to keep it highlighted after mouse up). Calling [NSStatusButton setHighlighted:] in its action doesn't work because it seems to unhighlight itself once

Left vs Right Click Status Bar Item Mac Swift 2

匆匆过客 提交于 2019-11-29 03:48:30
I have been trying to develop a simple program that sits in the Mac's status bar. I need it so that if you left click, it runs a function, but if you right click it displays a menu with an About and Quit item. I have been looking but all I could find was command or control click suggestions however I would prefer not to go this route. Thanks in advance and any help appreciated! Michael Samoylov Swift 3 let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength) if let button = statusItem.button { button.action = #selector(self.statusBarButtonClicked(sender:))

Get Notification of NSStatusItem frame change?

人走茶凉 提交于 2019-11-29 02:37:55
In an app that uses a NSStatusItem with a custom view like this: ... how can you get notifications when: The status bar gets hidden because of a full screen app The status item moves position because another item is added/removed/resized? Both are necessary to move the custom view to the right position when the item changes places. There is a method -[NSStatusItem setView:] . When you set a custom view for your status item, this view is automatically inserted into a special status bar window. And you can access that window using a method -[NSView window] to observe its

How to get frame for NSStatusItem

℡╲_俬逩灬. 提交于 2019-11-28 21:40:52
Is it possible to get the frame of a NSStatusItem after I've added it to the status bar in Cocoa? When my app is launched, I am adding an item to the system status bar, and would like to know where it was positioned, is possible. If you have set a custom view on the status item: NSRect statusRect = [[statusItem view] frame]; NSLog(@"%@", [NSString stringWithFormat:@"%.1fx%.1f",statusRect.size.width, statusRect.size.height]); Otherwise I don't think it's possible using the available and documented APIs. Edit: Incorporated comments. The following seems to work - I have seen similar solutions for

NSStatusItem change image for dark tint

纵饮孤独 提交于 2019-11-28 16:01:06
With OSX 10.10 beta 3, Apple released their dark tint option. Unfortunately, it also means that pretty much all status bar icons (with the exception of Apple's and Path Finder's that I've seen), including mine, remain dark on a dark background. How can I provide an alternate image for when dark tint is applied? I don't see an API change on NSStatusBar or NSStatusItem that shows me a change, I'm assuming it's a notification or something reactive to easily make the change as the user alters the tint. Current code to draw the image is encased within an NSView : - (void)drawRect:(NSRect)dirtyRect

Drag and Drop with NSStatusItem

喜你入骨 提交于 2019-11-28 03:36:41
I'm trying to write an application that allows the user to drag files from the Finder and drop them onto an NSStatusItem . So far, I've created a custom view that implements the drag and drop interface. When I add this view as a subview of an NSWindow it all works correctly -- the mouse cursor gives appropriate feedback, and when dropped my code gets executed. However, when I use the same view as an NSStatusItem's view it doesn't behave correctly. The mouse cursor gives appropriate feedback indicating that the file can be dropped, but when I drop the file my drop code never gets executed. Is

How to get the on-screen location of an NSStatusItem

本小妞迷上赌 提交于 2019-11-27 19:09:42
I have a question about the NSStatusItem for cocoa in mac osx. If you look at the mac app called snippets (see the movie at http://snippetsapp.com/ ). you will see that once you clicked your statusbar icon that a perfectly aligned view / panel or maybe even windows appears just below the icon. My question is ... How to calculate the position to where to place your NSWindow just like this app does? I have tried the following: Subclass NSMenu Set the view popery for the first item of the menu (Worked but enough) Using addSubview instead of icon to NSStatusItem this worked but could not get

Left vs Right Click Status Bar Item Mac Swift 2

落花浮王杯 提交于 2019-11-27 17:50:29
问题 I have been trying to develop a simple program that sits in the Mac's status bar. I need it so that if you left click, it runs a function, but if you right click it displays a menu with an About and Quit item. I have been looking but all I could find was command or control click suggestions however I would prefer not to go this route. Thanks in advance and any help appreciated! 回答1: Swift 3 let statusItem = NSStatusBar.system().statusItem(withLength: NSVariableStatusItemLength) if let button

Cocoa Keyboard Shortcuts in Dialog without an Edit Menu

跟風遠走 提交于 2019-11-27 17:03:40
I have an LSUIElement application that displays a menubar status item. The application can display a dialog window that contains a text field. If the user right-clicks/control-clicks the text field, a menu appears that allows cut, copy, paste, etc. However, the standard Command-X, Command-C, and Command-V keyboard shortcuts do not work in the field. I assume this is because my application does not provide an Edit menu with those shortcuts defined. I've tried adding an Edit menu item to my application's menu, as suggested in the Ship Some Code blog, but that did not work. The menu items in the