Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Always keep an application open System
If you have some app that you always want to keep open -- in my case it's Stickies and DragThing, which I use frequently -- it's easy to set up the computer to do that for you.

For example, to keep Stickies permanently open, remove Stickies from the login items for your account (if you've placed it there), quit Stickies, and then create the following plist file in the LaunchAgents folder of your home Library (~/Library/LaunchAgents) with the name user.launchkeep.stickies.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>user.launchkeep.stickies</string>
  <key>KeepAlive</key>
  <true/>
  <key>Program</key>
  <string>/Applications/Stickies.app/Contents/MacOS/Stickies</string>
</dict>
</plist>
Now load this launchd job by logging out of your account and logging back in or launch Terminal and enter:

launchctl load ~/Library/LaunchAgents/user.launchkeep.stickies.plist

Stickies will now effectively be un-removable -- any time it quits, crashes, or gets forced-quit it will pop right back up. If fact, in order to quit the app at any time other than logout or shutdown you'll need to disable the job; In Terminal type

launchctl remove user.launchkeep.stickies

Or you can set up a script that does that for you.

Note that you have to use the path to the inner executable, not the path to the app package - you can find this by right clicking on the app icon, choosing Show Package Contents, and navigating down to the MacOS folder where the main executable is stored. If you do something wrong, the general result will be that the app is not only kept alive, but in fact keeps launching every 10 seconds or so (launchd's throttle time-out), so that it keeps grabbing screen focus, which is very annoying. if that happens, just unload the plist, make sure it is correctly written and the app is quit, then load it again.

[crarko adds: I haven't tested this one.]
    •    
  • Currently 3.44 / 5
  You rated: 5 / 5 (9 votes cast)
 
[21,011 views]  

Always keep an application open | 22 comments | Create New Account
Click here to return to the 'Always keep an application open' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Always keep an application open
Authored by: lemac on Jun 20, '11 10:59:24AM

This is great. Thanks for posting. Now would there be a way to keep the application hidden?



[ Reply to This | # ]
Always keep an application open
Authored by: shpokas on Jun 20, '11 12:01:24PM

There is, already. Read this: http://www.cocoadev.com/index.pl?LSUIElement



[ Reply to This | # ]
Always keep an application open
Authored by: lemac on Jun 21, '11 03:47:10PM

Thanks for the suggestion. This is quite technical. I am in no way a developer and got lost in the instruction. I was hoping for a simple solution like the one presented in this hint. I don't mind having the icon showing the application open in the dock but would like to hide the window.



[ Reply to This | # ]
Always keep an application open
Authored by: shpokas on Jun 21, '11 11:50:26PM

Maybe this explanation can help, if you want to hide dock icon. (From here: http://growl.info/documentation/hardwaregrowler.php)

Disabling the dock icon:
Because HG doesn't really have any user-interaction features, you may follow these steps to disable the dock icon. Navigate to wherever you placed HG and right-click on it and select "Show Package Contents." Open up contents and then right-click Info.plist. Highlight "Open With" and select TextEdit from the list (If TextEdit is not in the list, choose "Other..." and navigate to TextEdit and click "Open").
Paste the following just after <dict>:
<key>LSUIElement</key>
<true/>



[ Reply to This | # ]
Always keep an application open
Authored by: tedw on Jun 20, '11 03:39:01PM

Not directly through launchd; but then again, I'm not sure why you'd want to do that, so maybe I'm misunderstanding the question. what app are you talking about, and what do you want hidden?



[ Reply to This | # ]
Always keep an application open
Authored by: lemac on Jun 21, '11 05:16:30AM

I remotely connect to my computer at home with an application called TeamViewer. When TW launches it opens a window which provide login information. If you close that window, TW quits. You can't keep the application open without the window.

There are other members of the family who use this computer. They are sometimes distracted and close the window and with it, the application. Your hint comes very handy to prevent this. However, to prevent confusion it would be better if the window would hide when the application opens. You can do this when you add an application in the Login Items.



[ Reply to This | # ]
Always keep an application open
Authored by: tedw on Jun 21, '11 08:48:45AM

Badly designed port of a windows app. You should write the developers and tell them that this is un-Mac-like behavior and they should fix it.

That being said, this is not (IMO) how you should approach this issue. It would be better for you to create a second user account just for work and enable fast user switching. This way you have a handy menu that lets you switch between accounts - you can log into your work account, start the application, then switch to the other account and let your family have at it: the work account and the TW app will run in the some strange background dimension where no one can see it. Just tell your family not to go into your work account on pain of eternal grounding. (you could password the account if you really wanted to, but it would add the extra stop of entering the password when you wanted access).

In fact, you could set up individual accounts for each of your family members so that they could all do their stuff without it mixing in with everyone else's stuff. You'd want to max out your machine's RAM (fast user switching keeps each logged-in account active, which hogs memory).



[ Reply to This | # ]
Always keep an application open
Authored by: Anonymous on Jun 21, '11 11:00:23AM

"you could password the account if you really wanted to"

Oh my goodness. Are you seriously suggesting that users don't apply a password by default? This isn't 1980, you know...



[ Reply to This | # ]
Always keep an application open
Authored by: tedw on Jun 21, '11 11:45:17AM
You'd be surprised. I'm always seeing people over in the forums who share their user accounts with friends, college roommates, random acquaintances. People, I swear…

However, If you're already sharing a user account with your family (and I assume this is a desktop that doesn't travel out of the house where other people could get physical access), then putting a password on your work account would just be to keep your kids/spouse out of it - it wouldn't really be needed for security reasons (unless you're worried about someone breaking into your house late at night so they could update their facebook page).

That being said, if you're going to have an account with no password, do not under any circumstances make it an administrator account or put it on the sudoers list. That would just be dumb.

[ Reply to This | # ]

Always keep an application open
Authored by: lemac on Jun 21, '11 03:04:18PM

Actually, this is a common behavior for applications that won't open more than one window at a time. For instance, Apple's own iPhoto, System Preferences, Dictionary and Calculator will quit on closing the window.

I appreciate your suggestions. I am already using multiple accounts on the computer but I also do remote support for extended family and friends and would like to keep it as simple as possible. A window auto-hide at launch would be just perfect in most cases.



[ Reply to This | # ]
Always keep an application open
Authored by: lemac on Jun 21, '11 03:44:05PM

Thanks for the suggestion. This is quite technical. I am in no way a developer and got lost in the instruction. I was hoping for a simple solution like the one presented in this hint. I don't mind having the icon showing the application open in the dock but would like to hide the window.



[ Reply to This | # ]
Always keep an application open
Authored by: tedw on Jun 21, '11 04:02:47PM

Google the system preferences app Do Something When - I think you can set that up to automatically run a script to hide the app when it's launched.



[ Reply to This | # ]
Always keep an application open
Authored by: lemac on Jun 22, '11 06:53:53AM

I installed this Preference Pane. You can set it to open a document or an app when an app is launched (no option to run a script as such). I am not familiar with applescripts but managed to create an app with Automator that hides the window after launching TeamViewer. It does what I wanted to do. I am an happy camper now! Thanks tedw and everybody else for the kind and appreciated inputs.



[ Reply to This | # ]
Always keep an application open
Authored by: trosberg on Jun 22, '11 01:03:42PM
I thought keeping and hiding an app is easier to carry out with an AppleScript app. An icon more in your Dock, though.
(*
ApplicationHider
Keeps an application running. Hides it, when not in use.
Paste into AppleScript Editor. Save as an application with 'Stay open' ticked. 
Add the script app to your login items in System Preferences.
Tuomas Rosberg 2011
*)

property appName : ""
property firstRun : false

on run
   if firstRun is false then -- this script app hasn't been opened
      set anApp to choose application -- launches and returns item application
      set appName to name of anApp
      set firstRun to true
   else -- firstRun is true in subsequent runs, continue to idling
   end if
end run

on idle
   tell application "System Events"
      if exists of application process appName then
         if frontmost of application process appName is false then
            set visible of application process appName to false
         end if
      else -- the app process does not exist
         tell application "Finder" to launch application appName
      end if
   end tell
   return 3 -- seconds to idle
end idle


[ Reply to This | # ]
Always keep an application open
Authored by: mingo on Jun 20, '11 05:49:48PM

Doesn't this LaunchAgent prevent you from logging out? Every time you try to log out, Stickies relaunches and blocks the logout.



[ Reply to This | # ]
Always keep an application open
Authored by: tedw on Jun 20, '11 09:52:20PM

No, it shouldn't. launchd has a special procedure for logout and shutdown, in which it disables launchd jobs (for precisely this reason, I think - the KeepAlive key is commonly used for certain kinds of background tasks).



[ Reply to This | # ]
Always keep an application open
Authored by: lemac on Jun 21, '11 05:22:38AM

I rebooted several times to test this claim and the shut down was cancelled the first time only. I don't know why it happened only the first time.



[ Reply to This | # ]
Always keep an application open
Authored by: Anonymous on Jun 21, '11 11:01:37AM

Maybe you had "sudo launchctl load [...]" by mistake?



[ Reply to This | # ]
Always keep an application open
Authored by: lemac on Jun 21, '11 03:10:46PM

You lost me here. All I did is implementing the steps as instructed and did not change anything in between reboots.



[ Reply to This | # ]
Always keep an application open
Authored by: jpclark49 on Jun 21, '11 08:42:29PM

This is pretty cool, Thanks! It works fine on my 10.5 system, but while it's loaded on 10.4, it doesn't seem to function. Any quick suggestions? Thanks again!



[ Reply to This | # ]
Always keep an application open
Authored by: tedw on Jun 21, '11 09:49:17PM
the KeepAlive key was introduced in 10.5. for 10.4, you could try replacing KeepAlive/true with OnDemand/false. Unfortunately I don't have a 10.4 partition to test this on

[ Reply to This | # ]
Always keep an application open
Authored by: jpclark49 on Jun 22, '11 05:52:14AM

You 'da MAN! I just made this change on my 10.4 system and it's working!

Thank you!!



[ Reply to This | # ]