I'm developing a swift Mac OS app that works only in the status bar (with a popover) with Application is background only
set to true
.
Inside the popover the user can interact with a button to save an image, more specifically the following function is triggered:
@IBAction func saveImage(sender: NSButton) {
self.closePopover()
let dialog = NSSavePanel()
let date = Date()
let formattedDate = getFormattedDate(date: date, format: "yyyy-MM-dd")
let formattedTime = getFormattedDate(date: date, format: "HH.mm.ss")
dialog.level = .modalPanel
dialog.title = "Choose a destination"
dialog.nameFieldStringValue = "Screenshot \(formattedDate) at \(formattedTime)"
dialog.showsResizeIndicator = true
dialog.showsHiddenFiles = false
dialog.canCreateDirectories = true
dialog.allowedFileTypes = ["png"]
if (dialog.runModal() == .OK) {
// Pathname of the file
if let result = dialog.url {
self.screenshot!.savePNGRepresentationToURL(url: result)
}
} else {
// User clicked on "Cancel"
return
}
}
The problem is that:
- If I put
Application is background only
=true
:
I can't interact with the NSSavePanel (can't change thesave as
field) and if I write inside that box, the text is written in the last application I was interacting (the focus is not really on the modal). - If I put
Application is background only
=false
:
the NSSavePanel works perfectly fine but that is not a good solution because I don't want to have the icon to appear in the dock
So the problem is clearly linked to the Application is background only
but I didn't find a way to have both:
- no app icon in the dock
- good interaction with the NSSavePanel