• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Any way to ensure that my app will terminate before Finder does on log out, restart, etc.?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Any way to ensure that my app will terminate before Finder does on log out, restart, etc.?


  • Subject: Re: Any way to ensure that my app will terminate before Finder does on log out, restart, etc.?
  • From: Mark Douma <email@hidden>
  • Date: Mon, 13 Aug 2007 03:25:13 -0400


On Aug 13, 2007, at 12:02 AM, Steve Voida wrote:

I have a Cocoa app that makes a couple of AppleScript calls to the Finder
just before terminating to clean up my app's state (setting Finder Comments
on files, restoring the desktop background...things of that nature). The app
typically makes all of these calls in a very short time; they're not
expensive or computationally-expensive scripting requests.


That said, when the user (or the system) invokes a "log out," "restart," or
"shut down" request, the Finder often completes its termination before my
application does, making my AppleScript calls silently fail and leaving bits
of pieces of my clean-up process undone. Is there any way for my application
to register as a sort of delegate on Finder to delay its termination just
long enough for my clean up process to complete, or to otherwise prioritize
my application's receipt of the applicationShouldTerminate: message so that
I at least have a half-decent head start in tidying up? I was hoping that
there might be something useful in NSWorkspace I could use or an Apple
Events call that I could manufacture, but I'm coming up empty on ideas....


Thanks in advance,
Steve Voida
Georgia Tech


You could try playing around with NSWorkspace's NSWorkspaceWillPowerOffNotification.

In your .m file, do something like this (disclaimer: typed in Mail.app):

@interface YourClass (Private)
- (void)finderCleanup:(NSNotification *)notification;
@end

- (id)init {
if (self = [super init]) {
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(finderCleanup:) name: NSWorkspaceWillPowerOffNotification object:nil];
// the rest of your stuff
}
return self;
}


- (void)dealloc {
// be sure to remove yourself. N.B. make sure it's NSWorkspace's notificaton center, not the standard NSNotificationCenter


[[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self];
// rest of your stuff
[super dealloc];
}


- (void)finderCleanup:(NSNotification *)notification {
	// do your Finder cleanup here.
	// send some message to keep the Finder busy if necessary?
}

Hope this helps,

Mark Douma


------------------------------------------------------------------------ ---
Mark Douma
Grand Rapids, MI, USA
email@hidden
http://homepage.mac.com/mdouma46/
------------------------------------------------------------------------ ---



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Any way to ensure that my app will terminate before Finder does on log out, restart, etc.? (From: "Steve Voida" <email@hidden>)

  • Prev by Date: Re: file reading/writing over 2 gig
  • Next by Date: Re: Which profile is applied in converting PDF/EPS images from CMYK to RGB?
  • Previous by thread: Any way to ensure that my app will terminate before Finder does on log out, restart, etc.?
  • Next by thread: Core Data relationship question
  • Index(es):
    • Date
    • Thread