Mac OS X- How to catch Logoff / Restart / Shutdown notifications and do few things before app/proce

Discussion in 'Mac Programming' started by GokulKrish, Apr 12, 2016.

  1. GokulKrish macrumors newbie

    Joined:
    Apr 12, 2014
    Location:
    Chennai
    #1
    Mac OS X- How to catch Logoff / Restart / Shutdown notifications and do few things before app/process terminates (Backgroud apps / Commandline tool ).

    With foreground apps , I can achieve the same by using this delegate .
    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender

    But I do not want my application to run in foreground (i.e) shouldn't be shown on DOCK and App switcher . So I gave NSUIElement to 1 .
    But during Logoff / shutdown , it does not allow to complete the -applicationShouldTerminate part . It kills the process midway .

    Can any one please tell me how to achieve this using an app / commandline tool ?!!!

    (In short, I need a Mac application that runs in background but gets applicationShouldTerminate's behaviour )

    Thanks in advance .

    PS : I already have tried NSApplicationActivationPolicy , it does same as NSUIElement 1 .


    Regards ,
    Gokul
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    Maybe take a look at notifications. NSWorkspaceWillPowerOffNotification seems like a good place to start. There's some other stuff if you look at the documentation for NSWorkspace that might be useful. I've not used it myself, I'm afraid so I don't know whether you could pause shutdown for long enough for your app to do what it needs to do or not. Hopefully that at least gives you an idea though!

    Good luck!
     

Share This Page