Daily policies: 24 hours or each day?

New Contributor

I've got a policy that launches a webpage each day in the user's browser. It's set to run once per day, but it seems that Casper Suite interprets this as a 24-hour period, rather than a 12am - 11:59pm period.

My question is: can I create a policy that will consistently run a script whenever the computer is turned on, but only during certain hours, and will run based on the day as we think of it, not on a 24 hour period?

Basically, we want to launch a webpage each morning on a person's computer. But if an employee shows up at 1pm and activates the policy, it seems it won't run again until 1pm the next day, even if they show up at 9am. Am I missing something? Is there a way to do this? Thanks!


Valued Contributor II

You are correct by "Once a Day" mean Once every 24 Hours.

When you say "whenever the computer is turned on", do you mean full boot or waking from sleep? If its full boot, I'd say use the trigger for Login as the policy will run whenever the user does a full login (not wake or coming out of screensaver).

Legendary Contributor III

Like @ddcdennisb said, it does mean once every 24 hours, so the initial time, or at least the last time that the policy ran is going to be the next starting point of when it will run the following day, and don't forget about the random delay added to the policy run if it's being called by the recurring check-in trigger.
You can direct policies to only run between certain hours by way of telling it when NOT to run, which may prevent it from running late in the afternoon through the following morning, but you may run into issues with that since if someone misses the time window, the policy will be skipped on their Mac for that day entirely.

If the Macs aren't being booted up and/or logged into by users as mentioned above, then the only other way I can think of to do this would be to have the policy designed to run a "Before" script that checks to see if the policy ran anytime that day (working hours) and if not, call the actual policy that opens the webpage (or maybe just do it directly in the script) by an id or a custom trigger. And then set the policy that runs said script to run on each check-in. It will keep running every x minutes, but will skip calling the true policy if it sees that the policy ran at any point that day. This can be checked either by scanning the jamf.log for that policy and getting the timestamp, or by having the real policy drop some kind of timestamp in a log file on success that can be checked by the before script.

I'm not sure how you're opening that webpage on the user's computers, but I all the above could be integrated into a single script. The script is called by the policy (on the recurring check-in trigger) The script checks a local log file for when the webpage was last opened, and if it was within that same day, it exits silently. If it was the day before, open the webpage and update the local log's timestamp. That way you aren't relying on that 24 hour timespan the JSS uses.

Contributor III

@benbarrett To achieve your desired behavior you could use a Policy to install a LaunchAgent that's triggered by a StartCalendarInterval to run at a specific time of day and open your desired URL. If the LaunchAgent isn't able to run at the specified time, e.g. the computer is asleep, it will run when the computer wakes up. If you only want to have the URL opened during a specific window have the LaunchAgent run a script that can evaluate the time it's being run and decide if the URL should be opened.

LaunchControl from soma-zone is a great tool for working with LaunchAgents, and they even have a launchd Primer.