If I try to use Visual Studio Code (on macOS 10.15) to edit my crontab, it opens an empty file without the contents of my crontab.
$ VISUAL='code' crontab -e
crontab: no changes made to crontab
I didn't actually expect this to work (without -w
) but include it for completeness. But when I add the -w
it still fails.
$ VISUAL="code -w" crontab -e
crontab: code -w: No such file or directory
crontab: "code -w" exited with status 1
It occurred to me that there may be some weirdness with quoting, but neither single quotes nor the following fixed anything:
$ function codew() {
function> code -w "$1"
function> }
$ export VISUAL='codew'
$ crontab -e
The problem seems to be that the crontab's tempfile is not actually present. But how do I solve this? How can I use VS Code to edit crontabs?
The very first time you issue the crontab command with the -e (edit) option in a Bash terminal, you're asked to pick the editor you'd like to use. Type crontab , a space, -e and press Enter. The editor you select is then used to open your cron table.
Use the crontab -e command to open your user account's crontab file. Commands in this file run with your user account's permissions. If you want a command to run with system permissions, use the sudo crontab -e command to open the root account's crontab file.
touch ~/code-wait.sh
:#!/bin/bash
OPTS=""
if [[ "$1" == /tmp/* ]]; then
OPTS="-w"
fi
/usr/local/bin/code ${OPTS:-} -a "$@"
chmod 755 ~/code-wait.sh
.bashrc
or .bash_profile
or .zshrc
:export VISUAL=~/code-wait.sh
export EDITOR=~/code-wait.sh
EDITOR='code' crontab -e
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With