Remembering running program on shutdown

Discussion in 'Mac Programming' started by thriftinkid, Jan 5, 2009.

  1. thriftinkid macrumors regular

    Mar 24, 2008
    I have my computer set up for an automatic shutdown and startup on a daily basis. I have a specific program that I would like to start up the next morning with my computer, but only if it had been running when the computer shutdown the night before. If not, it should not load up. Is there a way that I can add a section in my startup/shutdown script that will check for that, and execute it the next morning if need be? I'm writing in applescript. I know it's not particularly reliable, but then again, I'm not a programmer. So it's basically my crutch into this new world. Thanks guys!
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    If you control the program (it doesn't sound like it) i would use a file to indicate if the program was running, and remove it otherwise.

    Since you don't, i would take the tact of parsing the output of ps to see if the process is running at shutdown, and record whether it is or not with the contents of a file (or simply the presence or absence of a file). There may be a more "direct" means to see if a program is running in applescript, but i am not familiar enough with it to say. In any event, even if you can determine if the process is running in "pure" applescript, you'll still need a way to store this to pick up the value on the next run.


    EDIT: I thought of another option. You could always launch this program through a shell script. The script could touch a file, run the program in question, then delete the file when it's done. I guess it depends on when in the shutdown process your applescript ran. It would have to be before the OS kills the program so you can still see the file there.
  3. Consultant macrumors G5


    Jun 27, 2007
    FYI, you DO NOT need to shut down OSX every day.

    Have you tried SLEEP? For most users, restarts are only needed when there is a system software update.
  4. Darkroom Guest


    Dec 15, 2006
    Montréal, Canada
    off-topic, but...

    honestly... i maybe restart my computer once a month...

    command-option-eject is the only power button i truly know :p. although setting a top right hot corner to activate sleep works really well...
  5. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Apple actually specifically recommend not turning your computer on and off all the time. The only time you should turn it off is when you go away for a few days.

Share This Page