Executing code on, or after a certain time/date?

Discussion in 'Mac Programming' started by BadWolf13, Aug 15, 2012.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    I'm looking for a way to execute an app, or a block of code at or after a certain time. I've used cron and crontab in the terminal to arrange certain programs to run weekly at the certain date/time. However, if the computer is off at the time specified, the program doesn't run at all. What I need to do in this new application is have a program run at a certain date/time if the computer is on, or start running when the computer is turned on for the first time after that date/time has passed. Any ideas?
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Have you tried launchd ?

    From the launchd.plist man page :

    Info : http://www.devdaily.com/mac-os-x/mac-osx-startup-crontab-launchd-jobs
    https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPSystemStartup/Articles/LaunchOnDemandDaemons.html
     
  3. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #3
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    I'll toss "at" out there for you to test. Its job list should survive reboot, so it may run those jobs the first chance it gets. No experience with this, just something else to check out.

    -Lee
     
  5. Mac_Max macrumors 6502

    Joined:
    Mar 8, 2004
    #5
    Or use cron/launchd to run a bash script that logs if the app has been run within x period of time and if not, runs it. Then set the script as a startup item as well.
     
  6. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #6
    Thanks Lee, I'll take a look into the "at" command.

    Max, do items set as startup items run when you awake from sleep, when you log in, or just when you turn on the computer?
     
  7. mrichmon macrumors 6502a

    Joined:
    Jun 17, 2003
    #7
    "anacron" is a command that behaves like cron with the exception that it will run commands that were scheduled while the machine was sleeping or powered off. The commands scheduled to run when the machine is sleeping or powered off will be run when the machine is next awake.

    anacron can be installed using fink or mac ports.
     

Share This Page