Do MacOS Mojave or Catalina have crontab equivalent?

Solution 1:

No, by default, there are no folders on macOS that allow any user to write into them, and then have the content executed automatically. This would be deemed a security risk by Apple.

cron and launchd

crontab exists on macOS. The use of cron is deprecated; Apple recommend launchd where possible.

With launchd each user has their own folder, ~/Library/LaunchAgents. Processes started through this mechanism are limited to the scope of the associated user's graphical user session.

launchd also provides locations for computer wide folders, see the manual page Files section on /Library/LaunchAgents and /Library/LaunchDaemons.

Watched Folders

macOS includes support for watched folders. These are likely the closest built-in solution to your description:

The ability to watch folders and take action on incoming items is a powerful automation technique that enables the creation of fully unattended workflows. A watched folder might be used, for example, to watermark incoming photos, convert them to PDF, and email them to clients for review. Many companies set up script servers—dedicated robot machines that watch folders and process detected items, allowing employees to offload tedious and repetitious work in order to focus on other important tasks.

In OS X, there are two primary ways to set up scripting-based watched folders: folder actions and stay open script apps.