Questions tagged [nsapplication-delegate]
33 questions
7
votes
1 answer
macOS: Is there any way to know when the user has tried to quit an application via its Dock icon?
Is there any way for a Cocoa application to detect when the user has tried to quit it via its Dock menu, and not by some other method?
Normally it's possible to catch and respond to quit events using the application delegate's…

Bri Bri
- 2,169
- 3
- 19
- 44
7
votes
1 answer
Why NSApplicationDelegate method openFiles: is being called multiple times on a multiple drag to the dock icon?
I have a Mac OS X application that implements the -(void)application openFiles: method to react to dragged files on the application icon.
I have a list of allowed filetypes in the document types section of my target info settings and the Finder…

Alfonso Tesauro
- 1,730
- 13
- 21
6
votes
0 answers
Prevent main AppKit app window from opening when loading a SwiftUI preview
I have a Mac App that's mostly written in AppKit. Over time, I'm adding new views in SwiftUI, and all the while I've been using SwiftUI previews to preview both my new SwiftUI views, and my old AppKit views/view controllers (see Previews are not…

Alexander
- 59,041
- 12
- 98
- 151
5
votes
3 answers
NSApplicationDelegate's applicationDidFinishLaunching is not being called
I've been trying to play with Swift 3, but I am unable to get started. The following code is compiling, however it does not log anything. Looks like applicationDidFinishLaunching is not being called. Am I missing some critical piece…

Allactaga
- 193
- 1
- 7
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
2 answers
Why isn't application:openFile: called when the application is already running?
I would like to handle open events when a user double-clicks on a file that was created by my application, or drags such a file onto the dock icon.
I've therefore implemented NSApplicationDelegate's application:openFile: and application:openFiles:…

Rich
- 7,348
- 4
- 34
- 54
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
0 answers
What happens when application:openFile returns NO instead of YES in my NSApplicationDelegate?
I'm learning some Objective-C/Cocoa and started to read up on handling open document events. Seems like the standard way is just via implementing application:openFile or application:openFiles in your NSApplicationDelegate.
So here's my little…

michael.bartnett
- 787
- 7
- 20
3
votes
1 answer
Crash on Application Quit
Can any one help me in resolving this crash. This happens when the App is quit but not always.
Application Specific Information:
objc_msgSend() selector name: respondsToSelector:
Performing @selector(terminate:) from sender NSMenuItem…

Abdul Naveed
- 567
- 2
- 9
3
votes
2 answers
NSApplicationDelegate application:openFile. Never reaches to openFile: function
I want to open a file dropping it on the app icon.
When I do it my app is opened so the file extension is well defined and related to my app.
But the application:openFile: function never is called. so I can't open the file dropped in my app.
I…

soulianis
- 31
- 1
- 2
3
votes
2 answers
Cannot get Apple's SimpleScripting example to work when using NSApplicationDelegate
I am trying to write a trivial Objective-C application: I just want an app that will display a word in the status bar and allow the word to be updated via AppleScript. To be honest, I know little about AppleScript and nothing about Objective-C. …

Aaron B.
- 31
- 2
3
votes
1 answer
How to automatically create new NSDocument if no documents are restored?
EDIT: It seems like the issue below only occurs (rather, fails to occur... :) when I run the from within Xcode (I'm on 4.4), rather than from Finder. Is this an Xcode bug, or am I missing something?
I want to create a new (untitled) NSDocument when…

justin k.
- 504
- 1
- 6
- 15
2
votes
1 answer
How to send and receive NSAppleEventDescriptor when using NSWorkspace to open URLs between apps?
NSWorkspace has the method open(_:withAppBundleIdentifier: [...] ):
Opens one or more files from an array of URLs.
func open(_ urls: [URL],
withAppBundleIdentifier bundleIdentifier: String?,
options: NSWorkspace.LaunchOptions = [],
…

pkamb
- 33,281
- 23
- 160
- 191
2
votes
0 answers
Main window is not always initialized in applicationDidFinishLaunching
I set background image for the main window of my app inside application delegate:
func applicationDidFinishLaunching(_ aNotification: Notification) {
if let mw = NSApplication.shared.mainWindow {
mw.isMovableByWindowBackground = true
…

Pablo
- 28,133
- 34
- 125
- 215
2
votes
1 answer
Mac launch daemon runtime never calls app delegate when starting during reboot
I'm working on a Mac OS X service that is managed as a launch daemon. It does not have any GUI, but it is structured as a Cocoa app run with NSApplicationMain.
It seems like even though there is no GUI, there is a problem - everything works fine…

Corbell
- 1,283
- 8
- 15