Questions tagged [nsapplication]

NSApplication is the central class in Apple's AppKit framework.

The NSApplication class is the central class in Apple's AppKit framework (). It is responsible for starting the main run loop and provides the central framework for your application’s execution.

References:

178 questions
5
votes
1 answer

What's the number in XCode's console in square brackets?

Possible Duplicate: iphone nslog output format 2012-07-25 16:25:08:491 MyProject[2488:403] App finished launching. This might be an easy question, but what are those numbers?
DrummerB
  • 39,814
  • 12
  • 105
  • 142
5
votes
1 answer

objc_getProtocol() returns NULL for `NSApplicationDelegate"?

I'm trying to use the objc_getProtocol() function to get a reference to the struct representing the NSApplicationDelegate protocol: Protocol *protocol = objc_getProtocol("NSApplicationDelegate"); However, for some reason, this always returns NULL.…
Greg Brown
  • 3,168
  • 1
  • 27
  • 37
4
votes
1 answer

Get Application badge of running applications

I'm not sure if this is possible, but I want to get the application badges of other running applications. So I'd like to get the text from Mail's badge or other apps like Adium. I've looked in NSWorkspace and NSRunningApplication and was not able…
Brian
  • 3,571
  • 7
  • 44
  • 70
4
votes
1 answer

How to stop() main thread NSApp run() event loop? (embedded in C++)

Here is a minimal reproductible example, if too long to read, go to next section with the problem, and then explore the code if needed. Minimal example: Let suppose a simple C++ command line: main.cpp #include #include "Wrapper.h" int…
Adrian Maire
  • 14,354
  • 9
  • 45
  • 85
4
votes
1 answer

applicationWillTerminate and applicationShouldTerminate don't get run on macOS?

I want to do some stuff when an application terminates, so I added applicationShouldTerminate: and applicationWillTerminate methods to my AppDelegate. However, when I run my app from XCode and then press ⌘Q, neither method gets called. Now I'm…
Noah
  • 496
  • 5
  • 12
4
votes
0 answers

Change macOS Dock Icon with Dark Mode Change in Swift

Xcode 11, Swift 5.1 I want to set a different dock icon for my macOS app depending on whether the user has dark mode enabled or not. This is what I have in my app delegate's applicationDidFinishLaunching method: if NSApp.effectiveAppearance.name ==…
Clifton Labrum
  • 13,053
  • 9
  • 65
  • 128
4
votes
1 answer

How can a Mac app determine the method used to launch it?

I have a Mac OS X application that is also a protocol handler (just as, for example, Safari is a protocol handler for the HTTP and HTTPS protocols). So when a user clicks a link of the form myscheme://some-kind-of-info in any application at all, my…
Scott Lahteine
  • 1,040
  • 11
  • 20
4
votes
2 answers

Stopping the NSApplication main event loop

I have an application consisting of the following single .m file: #import int main(int argc, char* argv[]) { [[[NSThread alloc] initWithBlock: ^{ sleep(2); dispatch_async(dispatch_get_main_queue(), ^{ …
Remko
  • 823
  • 6
  • 16
4
votes
1 answer

objective-c: How to use NSApplicationMain

Whats wrong with this program? // main.m #import #import int main(int argc, char *argv[]) { return NSApplicationMain(argc, (const char **)argv); } I try to compile and get this error: $ clang…
american-ninja-warrior
  • 7,397
  • 11
  • 46
  • 80
4
votes
1 answer

Open About App window programmatically on macOS

On Mac OS X, every app has an "About" window, which can be opened by clicking About [appname] in the [appname] menu in the menu bar. I'd like to open this window programmatically. Is this possible? EG: The About button for iTunes:
lukas
  • 2,300
  • 6
  • 28
  • 41
4
votes
2 answers

Any good way to set the exit status of a Cocoa application?

I have a Cocoa app which interacts with a server and displays a GUI. If there is a fatal error, I display an alert and exit. I'd like to set the exit status to a non-zero value to reflect that an error occurred, for ease of interaction with some…
user329441
  • 43
  • 1
  • 4
4
votes
3 answers

Cocoa: Can I prevent duplicated launching of one same application?

For example, a user puts my application on his/her desktop. Then he/she copied (instead of moving) it to the /Application folder. If the one at ~/Desktop has been launched, how can I prevent duplicated launching of the one at ~/Application? Any…
Andrew Chang
  • 1,289
  • 1
  • 18
  • 38
4
votes
3 answers

How to disable the auto-reopening of the last document?

How to disable the auto-reopening of the last document ? When I execute my application, it calls the method readFromData. But, the problem is that between my version 1 and my version 2, I changed the structure of the data that is saved by the…
Colas
  • 3,473
  • 4
  • 29
  • 68
4
votes
2 answers

How to know when a Cocoa app is about to quit?

I have a NSDocument based application. I'd like to know when the application is about to quit to validate some things. I'd hoped there might be a method such as a applicationWillQuit, but looking through the docs for both NSDocument and…
Joey FourSheds
  • 479
  • 1
  • 7
  • 18
4
votes
0 answers

How to disable the Help key and context sensitive help mode in OSX, especially with Qt

I have a cross platform Qt application that's running into some trouble in OSX. There's a feature that OSX has that I didn't even know existed - the 'Help' key. My MBP doesn't have one, and neither does my Apple wired keyboard purchased a year ago.…
Ted Middleton
  • 6,859
  • 10
  • 51
  • 71
1 2
3
11 12