How do I detect mouse-position in a menu bar app? - objective-c

I'm trying to develop a mac program using Xcode and cocoa. Im tying to make a menubar application in which you press a shortcut key and it will detect your mouse position on the screen. Is it possible to do this if so how can I do it?

If your looking for obtaining the mouse position in the screen simply use:
NSPoint point = [NSEvent mouseLocation];
As for the shortcuts well they only work if you are currently have the menubar menu open. If you want to be able to use the shortcut anywhere (whether the menubar is selected or not) use a global hotkey manager. I suggest DDHotkey which you can obtain from here:
https://github.com/davedelong/DDHotKey
Source:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/Reference/Reference.html

Related

Continuity camera contextual menu issue

The contextual menu in one NSTextView in my app does work and imports a sketch made on my iPad / iPhone.
My problem is that when another of my app's windows is visible, the contextual menu in its NSTextView does not connect to the iOS device.
Also, when this second window is visible, the menu no longer works in the other window.
I posted a screen recording to YouTube here: https://youtu.be/qWMUGdL7O8g
I tried changing firstresponder to no avail.

How to implement the Windows 10 OneNote Menu in Universal Windows Platform app

I would like to implement the OneNote app menu in my own UWP app. In the closed state, the menu only shows the 'hamburger' button, but when clicked a menu pane slides in from the left.
I have tried to use the SplitView, but it doesn't allow me to set the width to 0 when collapsed, always showing a narrow line on the left side. I also considered using the 8.1 Flyout control, but that doesn't see to animate the correct way.
So, what's the correct way to implement the OneNote menu behavior?
You need the SplitView, but don't mess with the width of its pane.
Instead, set the DisplayMode to Inline (or Overlay) and toggle the IsPaneOpen property.

Create a keyboard shortcut for a button in a windows app?

Create a keyboard shortcut for a button in a windows app?
I have an Autodesk Revit app which i use for CAD.
There is a button in this app that does a "Fit to view" command. You click it and a 3D view centers around an object.
The app does not allow me to bind this "action" to a keyboard shortcut in it's current version.
If you use a Spacepilot 3D mouse this action si available to one of its the buttons.
Is there any way to bind this to a keyboard shortcut using some kind of software?
Revit also allows extensions through it's API so this might be a way also.
Apparently there is a "Zoom to awesome" addin that uses the API to do that but only in plan view not 3d camera perspective views like you can do with the viewcube.
http://www.architecture-tech.com/2012/09/zoom-to-awesome.html

Use LSUIElement (aka no Dock icon) but retain the "File, Edit, View" menubar?

I want my app to have:
Menubar extra icon (by the clock)
App Menubar ("File, Edit, View, Etc")
I do not want my app to have:
Dock Icon
Is this possible? I am deploying for 10.6 and 10.7 via the Mac App Store if that matters.
Setting LSUIElement in the info.plist file removes the dock icon, but it also removes the menubar.
NSApplication's setActivationPolicy might be what you are after.
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
Please note the discussion:
Currently, NSApplicationActivationPolicyNone and
NSApplicationActivationPolicyAccessory may be changed to
NSApplicationActivationPolicyRegular, but other modifications are not
supported.Needs links to running application
As per NSApplicationActivationPolicyAccessory's documentation you may need to programmatically ensure that the menu bar appears.
You could create two "separate" applications. One that has a dock icon and menu items,the other one has just the icon by the clock.
When you click on the icon by the clock it launches the dock application. When you close the dock application the 'background' application stays running.
If that model will work for you then that's the way to go. But I would weigh that effort against what File-Edit-View will do for you.

Cocoa Application with Menubar but no Dock Icon / switch menu

This is yet one more of those "how to switch from running with a dock icon to running without one" questions with a twist.. I don't want the dock icon but I do want a menu bar when the application is at the front. Is that possible?
Running an application with LSUIElement set to 1 in the plist will launch the application without a dock icon, not showing up in the command-tab switch list and without a menu.
You can switch from that mode to the "normal" mode with all three switched on via SetSystemModeUI from 10.2 onwards and via NSApplication setApplicationActivationPolicy since 10.6, but crucially there is no way back to the previous mode (go figure).
So one way around this would be to launch with LSUIElement = 1 and then activate the menu bar when the application gets the focus and deactivate it on the application losing the focus.. alas I can't find a way of doing that.
Can anybody help?
Best regards,
Frank
I too was looking for a solution, but it turned out to be quite simple:
In the project file Info.plist need to add the key
"Application is agent (UIElement)" = YES
Unfortunately, this is not possible. You can only transform the process type in one direction (from a background app to a foreground app) and not the other way.