0

How can I make the application inactive when I click a button?

macOS, Swift, storyboard

(I could find some approximations but only in iOS. I am looking for macOS: Detect if the application in background or foreground in swift)

I can put the window at the bottom but it is still active:

view.window?.level = NSWindow.Level(rawValue:
NSWindow.Level.normal.rawValue - 1)
Nrc
  • 9,577
  • 17
  • 67
  • 114
  • I do not want to hide it. I want to put the only window of the app below and inactive – Nrc Apr 04 '21 at 16:17
  • 1
    Is [`NSApplication.deactive()`](https://developer.apple.com/documentation/appkit/nsapplication/1428428-deactivate) what you're looking for? – Alexander Apr 04 '21 at 16:43
  • @Alexander: it says Instance member 'deactivate' cannot be used on type 'NSApplication'; did you mean to use a value of this type instead? – Nrc Apr 04 '21 at 17:59
  • @Nrc Well yeah, it's an instance variable, you have to call it on your instance of `NSApplication`, usually accessed through the `shared` class property: `NSApplication.shared.deactivate`. I also made a typo in my first comment, I meant `deactivate`, not `deactive`. – Alexander Apr 04 '21 at 18:02
  • @Joakim It can be at the bottom but active. I need it to be inactive. See my edit of the question – Nrc Apr 04 '21 at 18:02
  • Which app should become active? – Willeke Apr 04 '21 at 19:17
  • @Alexander: I think that according to how I have asked, yours is the right answer. You should put that as an answer and I will accept it. On the other hand, I am not sure how it works. It seems that the window is not active but I am still in the app, I mean the app is active. To make the app inactive perhaps I should make another random app active or perhaps the Finder. Is that right? Do you know how? – Nrc Apr 05 '21 at 10:00
  • Remember, I asked how to make the app inactive, not how to make the window inactive – Nrc Apr 05 '21 at 10:29

0 Answers0