DEV Community

printfapps
printfapps

Posted on

Run a script every day on your Machine without cron

You have a script you want to run every morning. Mine builds a small tech news brief from Hacker News, commits it, and pushes it to a GitHub Pages site.

How do you do it?

You ask an AI, and get a crontab line:

0 8 * * * cd ~/morning-brief && python3 scripts/brief.py && git push
Enter fullscreen mode Exit fullscreen mode

Next morning, there's no new brief, and no error anywhere. cron runs your line with almost no environment: a short PATH, no ssh agent for git push. Whatever went wrong was sent to a local mailbox you never open.

You ask again, and get full paths, an ssh setting, and >> ~/brief.log 2>&1 at the end. Or a launchd plist: thirty lines of XML. It works, but checking on it means reading a log file, and changing the time means editing the crontab or reloading the plist.

With cmdbook, a schedule is a setting on a command you already run by hand.

Set schedule for your command

Here's how

1. Save the job as a command. Mine pulls, runs the script, commits only if there's something new, pushes, and prints the site address. It's the same command I click to publish by hand.

2. Schedule it. Automations → New schedule → Daily, 08:00, your time zone. Action: run the command. Save.

3. Right on time, it runs on its own. It runs the way it does when you click it, with your shell environment, so python3 and git push work. The output shows up in its panel, as if you'd clicked Run:

30 stories from Hacker News; 3 picks on the topics.
...
Published: https://printfapp.github.io/morning-brief/
Enter fullscreen mode Exit fullscreen mode

A minute later, the new brief is on the site.

4. See when it runs next. Hover over the command, and it lists the next three runs.

5. Every automation, in one list. Switch one off with its Enabled switch, or open it to change the time.

Two things to know. cmdbook has to be running for a schedule to fire. Mine sits in the menu bar with no window open. And a scheduled command can't stop to show a form, so write the values into the command instead of using prompts.

Automations are part of cmdbook Pro.

Try cmdbook here: printf.app/cmdbook

Top comments (0)