Mac background and foreground application with same datafile

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
With "Application is background only" in the .plist of your app, it is possible to specify that an app is background only. Apple calls this an "agent". This can be combined with an icon on the right side in the statusbar (apple bar/menubar) via nsstatusitem.

I want to make an app that runs continuously in the background. When the user starts (via a menu on the statusitem) the GUI app, it should look and act like a regular app with dock icon and menubar. The background app should also continue running at the same time. This is probably possible by just making two different apps. It is not a document-based app, but it is a core-data app. So the data and the datafile is (should? will? can't?) identical for both apps.

What would be the best approach to tackle this? Two separate apps (but how would you deal with the datafile issue) or 1 app where the .plist is changed on the fly (or is that not possible?). As always, thank you for your time and answer!
 

skunkworker

macrumors regular
Sep 9, 2007
177
11
So you are really asking for a daemon to run in the background and the gui justs hooks into it? What are you doing that requires it to run in the background?
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
So you are really asking for a daemon to run in the background and the gui justs hooks into it? What are you doing that requires it to run in the background?
My program should check with other computers on a regular basis, retrieve and store information and when necessary (depending on the data) report back to the user for further intervention. It should act as independently as possible and bother the user as little as possible. Maybe once a week, a few times tops, the user will have to do something. But it is important not to delay that intervention too much. That would just waste time. Messages will be displayed via growl. On the hand, if the user wants to check the status, (s)he should be able to start the gui itself via the statusbar icon.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
1
Portland, OR
I would probably have the background app handle interacting with the file, and the foreground app communicate with the background app.
 

MrFusion

macrumors 6502a
Original poster
Jun 8, 2005
599
0
West-Europe
I would probably have the background app handle interacting with the file, and the foreground app communicate with the background app.
I can try that. Syncing the two datafiles (one per app) is maybe also an option? I just started reading about that, not sure yet how straightforward that is.
 

Catfish_Man

macrumors 68030
Sep 13, 2001
2,579
1
Portland, OR
While convenient, I would not recommend NSDistributedNotificationCenter for that purpose. For example, it makes no guarantees that it won't drop notifications when heavily loaded.

Cocoa distributed objects or standard unix IPC methods are better choices.