18

I just have started to use crontab and have some problems with it. I have already read some posts about how to use it on macOS, but it still not working.

So, I write crontab -e, then edit it to */1 * * * * cliclick -w 1 m:3,3 (for example) - which mean repeat click in x=3;y=3 every 1 min. And nothing has changed. But, when I use just this command from the terminal everything is ok.

I have already tried to create a script.sh file, and the same situation: from hand-command it works, and from crontab isn't.

Maybe, I do something wrong? UPDATE: Full disk access crontab has.

UPDATE2: I tried do it again on the BigSur. First of all I use a more simple command like echo:

* * * * * echo 'test' >> /*/Desktop/text.txt And it works well. After that, I write my own script.sh

echo '2test' >> /Users/***/Desktop/t.txt
/usr/local/bin/cliclick -w 1 m:1,3
cliclick -w 1 m:55,44

And it the cliclick not working, as the other bin files located in /usr/local/bin/ (cliclick located in this path)

Note, that if I execute ./script.sh then cliclick works fine in both cases.

I thoroughly googled and found that run cliclick (and other) is NOT possible though crontab: https://github.com/BlueM/cliclick/issues/103

0x0000dead
  • 330
  • 1
  • 4
  • 12

5 Answers5

33

My Problem was, that cron had no access to the Disk, so it couldn't run my script. I had to give Full Disk Access for /usr/sbin/cron

See this blog post: https://blog.bejarano.io/fixing-cron-jobs-in-mojave/

roNn23
  • 1,532
  • 1
  • 15
  • 32
  • 1
    Still unable to run. Do you know any other reason why it may not run in MacOS? I am using Mojave 10.14.5. – mythicalcoder May 07 '20 at 15:41
  • I think there may be some inheritance going on here. A similar problem with Unison, where it ran fine from the terminal (iTerm), but not from my crontab. It wasn't resolved by giving Unison Disk access. Instead I had to give cron Disk access (and removed access from Unison). So maybe the top of the process tree is what needs access? – Ted Feb 15 '21 at 04:46
13

(macOS Big Sur Version 11.2.3)

First you have to verify whether a cron exists or not with crontab -l.

After you're done creating a cronjob, you'll see something like "crontab: installing new crontab". (If you don't see this message, the job hasn't been created and will not show when you run crontab -l)

To ensure that the cronjob executes, I've had to do what @roNn23 and @berkinet have suggested. Elaborating in case the linked article goes down:

Give "Full Disk Access" (under System Preferences > Security & Privacy > Privacy) to:-

  1. /usr/sbin/cron using the Go to folder shortcut "command + shift + G"
  2. Terminal.app
Saurabh
  • 5,176
  • 4
  • 32
  • 46
9

Give terminal.app Full Disk Access.

You need to authorize Full Disk Access for terminal.app in Settings > Security & Privacy > Privacy.

Joshua Pinter
  • 45,245
  • 23
  • 243
  • 245
berkinet
  • 91
  • 1
  • 2
  • 1
    You're the man now, dog. That was it. I added `cron` and even `crontab` but that wasn't doing the trick. Turns out I needed to add `terminal.app` as well. Thanks for this! – Joshua Pinter Jan 20 '21 at 23:41
  • Fascinating! Any explanation as to why these permissions are relevant to cron? Is it using Terminal.app to run the scripts (even though the scripts run in the background with no UI)? – corwin.amber Jul 17 '21 at 10:13
2

You can check if there are any errors while running the cron by configuring it as below.

*/1 * * * * cliclick -w 1 m:3,3 >> output.log 2>&1

the last part 2>&1 will redirect the STDERR to the output.log as well.

Sam
  • 143
  • 1
  • 8
  • For your path issue. You can try something like. */1 * * * * cd /Users/your-user-name/Desktop && ./cliclick.sh – Sam Dec 01 '19 at 08:55
  • can you try executing this command `/usr/local/Cellar/cliclick -w 1 m:3,3` in terminal and see what happens? – Sam Dec 01 '19 at 14:55
  • https://formulae.brew.sh/formula/cliclick - so, this is cliclick. It doesn't matter where I stay e.g /usr/local/Cellar/cliclick or just /Users or /. Actually, not understand what you mean: `/usr/local/Cellar/cliclick -w 1 m:3,3` , `/usr/local/Cellar/cliclick` is a way to folder, like a different way to brew utilities. If you mean cd /usr/local/Cellar/cliclick and then cliclick -w 1 m:3,3, so it correctly works. I have already solved the problem use while in c++, but it's bad idea, I think. Thank you – 0x0000dead Dec 01 '19 at 15:16
  • ok, i thought cliclick was installed in /usr/local/Cellar and thats the reason i wanted you to try that command. – Sam Dec 01 '19 at 15:46
0

If you have some variable in your profile, and you already have full disk access to corn and terminal you might also need to give source to your zshrc profile

You can try this:

* * * * * source ~/.zshrc ; /bin/zsh /Users/myuser/somescript.zsh
IPKISS
  • 1