Mac Osx Set Default Editor For Crontab


E Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables. After you exit from the editor, the modified crontab will be installed automatically. Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron. Click here: to return to the 'Using the 'cron' scheduler' hint. When you save your changes it will then parse the crontab you have set up and warn you if there are any obvious errors in it. Man crontab man 5 crontab man vi [| #] Using an external text editor for crontab. Mac OS X Hints; iPhone Central. OS X and many flavors of *nix come with Crontab, an excellent program to run unattended jobs. This short tutorial should allow you to set up your own Crontab jobs. Create a script you wish to run. For this example, I am going to use the awstats.pl script to update my stats. The command to run the update is.

Change the default UNIX editor | 6 comments | Create New Account
Click here to return to the 'Change the default UNIX editor' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.

Try using the great freeware from BareBones Software, TextWrangler. Install the command line tool 'edit' and then set your $EDITOR to 'edit -w'. Now the shell will wait for you to close the file before it continues. Combine it with sudo to edit protected files.

Not good if you are connecting to your mac remotely though.

As an aside, SubEthaEdit fans will appreciate see as a commine-line starter.

Isn't it funny when you have been doing this for such a long time that it never actually occured that others might be interested in this being posted as a hint :)

juggularity: Sweet! I've always seen BBEdit ask me about installing the CLI tools but never bothered to look into them.
encro: Yup..precisely why I wrote up the hint. It was one of those UNIX 101 things I learned back in the late-eighties that newbies really won't find on their own. :)

Try to use SubEthaEdit as editor.

As a former tcsh user I've had to learn some of the ways of bash, so I pass along this hint about where to put those changes you make, especially for all users of one computer.
For bash users (default shell now in Tiger) you can set a variable, for example, for individual users in the '~/.bash_profile' hidden file in their home directoy, or for all users of the same computer in '/etc/profile'.
If you have a lot of users for each computer at your workplace or computer lab, then the /etc/profile save time.
Three examples of how add directories to your command path, and one plain ol' set variable:
export PATH=$PATH:/opt/local/bin
export PATH=/usr/local/mysql/bin:$PATH
PATH='${PATH}:/usr/local/rush/bin'; export PATH
export NR_FONT_PATH='/Volumes/VFX/Shake/nreal/fonts/'
---
Mat X -- VFX Mac Tech

Active1 year, 4 months ago

I would like to use cron on my Mac. I choose it over launchd, because I want to be able to use my new knowledge on Linux as well. However, I cannot seem to get the crontab -e command to work. It fires up vim, I enter my test job:

But after saving and quitting (:wq),

says:

What am I doing wrong?

kenorb
80.9k34 gold badges451 silver badges465 bronze badges
mollerhojmollerhoj
7071 gold badge7 silver badges16 bronze badges

10 Answers

Just follow these steps:

  1. In Terminal: crontab -e.
  2. Press i to go into vim's insert mode.
  3. Type your cron job, for example:

  4. Press Esc to exit vim's insert mode.

  5. Type ZZ to exit vim (must be capital letters).
  6. You should see the following message: crontab: installing new crontab. You can verify the crontab file by using crontab -l.

Note however that this might not work depending on the content of your ~/.vimrc file.

mwfearnley
1,5551 gold badge15 silver badges25 bronze badges
Cao Manh DatMac Osx Set Default Editor For CrontabCao Manh Dat
1,8321 gold badge12 silver badges14 bronze badges

I've never had this problem, but I create a ~/.crontab file and edit that (which allows me to back it up, Time Machine or otherwise), then run

Has worked for me for 20+ years across many flavors of unix.

Michael CampbellMichael Campbell
1,4381 gold badge14 silver badges20 bronze badges

NOTE: the answer that says to use the ZZ command doesn't work for me on my Mavericks system, but this is probably due to something in my vim configuration because if I start with a pristine .vimrc, the accepted answer works. My answer might work for you if the other solution doesn't.

On MacOS X, according to the crontab manpage, the crontab temporary file that gets created with crontab -e needs to be edited in-place. Vim doesn't edit in-place by default (but it might do some special case to support crontab -e), so if your $EDITOR environment variable is set to vi (the default) or vim, editing the crontab will always fail.

To get Vim to edit the file in-place, you need to do:

That should enable you to update the crontab when you do crontab -e with the :wq or ZZ commands.

You can add an autocommand in your .vimrc to make this automatically work when editing crontabs:

Another way is to add the setlocal nowritebackup to ~/.vim/after/ftplugin/crontab.vim, which will be loaded by Vim automatically when you're editing a crontab file if you have the Filetype plugin enabled. You can also check for the OS if you're using your vim files across multiple platforms:

Editor
Dave MeybohmDave Meybohm

The use of cron on OS X is discouraged. launchd is used instead. Try man launchctl to get started. You have to create special XML files that define your jobs and put them in a special place with certain permissions.

You'll usually just need to figure out launchctl load

Edit

Css editor for mac. Reviews of Mac CSS Editors. By Chris Coyier On October 8, 2007. There is some very nice software out there for creating and editing CSS files. To be perfectly honest, I wish they’d make a Mac version of it one of these days, but hands down it’s the best XHTML/CSS editor on the PC simply because of it’s simplicity, live previews,.

Pdf editor for mac app. • Security: all downloadable software must be 100% virus-free and malware-free. They are, however, by no means the industry standards.

If you really do want to use cron on OS X, check out this answer: https://superuser.com/a/243944/2449

Community
AndyAndy
6,8905 gold badges26 silver badges32 bronze badges

I did 2 things to solve this problem.

  1. I touched the crontab file, described in this linkcoderwall.com/p/ry9jwg (Thanks @Andy).
  2. Used Emacs instead of my default vim: EDITOR = emacs crontab -e (I have no idea why vim does not work)

crontab -lnow prints the cronjobs. Now I only need to figure out why the cronjobs are still not running ;-)

Visual basic editor for mac. Combined with the work to improve our integration of various language services, our aspiration is to bring similar levels of editor productivity from Visual Studio to Visual Studio for Mac. Improving the performance and reliability of the code editor Improving the typing performance and reliability is our single biggest focus area for Visual Studio 2019 for Mac. We plan to replace most of the internals of the Visual Studio for Mac editor with those from Visual Studio.

mollerhojmollerhoj
7071 gold badge7 silver badges16 bronze badges

How To Use Crontab Editor

As has been mentioned cron is deprecated (but supported), and launchd is recommended for OS X.

This is taken from developer.apple.com

Effects of Sleeping and Powering Off

If the system is turned off or asleep, cron jobs do not execute; they will not run until the next designated time occurs.

If you schedule a launchd job by setting the StartCalendarInterval key and the computer is asleep when the job should have run, your job will run when the computer wakes up. However, if the machine is off when the job should have run, the job does not execute until the next designated time occurs.

All other launchd jobs are skipped when the computer is turned off or asleep; they will not run until the next designated time occurs.

Consequently, if the computer is always off at the job’s scheduled time, both cron jobs and launchd jobs never run. For example, if you always turn your computer off at night, a job scheduled to run at 1 A.M. will never be run.

Roobie NubyRoobie Nuby

In user crontab (crontab -e) do not put the user field.

Correct cron is:

Syntax with user field is for /etc/crontab only:

kenorb
80.9k34 gold badges451 silver badges465 bronze badges
user3130043user3130043

The error crontab: temp file must be edited in place is because of the way vim treats backup files.

To use vim with cron, add the following lines in your .bash_profile
export EDITOR=vim
alias crontab='VIM_CRONTAB=true crontab'

Source the file:
source .bash_profile

And then in your .vimrc add:
if $VIM_CRONTAB 'true' set nobackup set nowritebackupendif

This will disable backups when using vim with cron. And you will be able to use crontab -e to add/edit cronjobs.

On successfully saving your cronjob, you will see the message:
crontab: installing new crontab

Source:
http://drawohara.com/post/6344279/crontab-temp-file-must-be-edited-in-placeenter link description here

SaurabhSaurabh
Mac os x set default editor for crontab format

As the previous posts didn't work for me because of some permissions issues, I found that creating a separate crontab file and adding it to the user's crontab with the -u parameter while root worked for me.

ShaneMitShaneMit

The above has a mix of correct answers. What worked for me for having the exact same errors are:

1) edit your bash config file

$ cd ~ && vim .bashrc

2) in your bash config file, make sure default editor is vim rather than vi (which causes the problem)

export EDITOR=vim

3) edit your vim config file

$cd ~ && vim .vimrc

4) make sure set backupcopy is yes in your .vimrc

Mac Os Cron

set backupcopy=yes

5) restart terminal

6) now try crontab edit

$ crontab -e

10 * * * * echo 'hello world'

You should see that it creates the crontab file correctly. If you exit vim (either ZZ or :wq) and list crontab with following command; you should see the new cron job. Hope this helps.

$ crontab -l

Jimmy M.G. LimJimmy M.G. Lim

Not the answer you're looking for? Browse other questions tagged macosvimcron or ask your own question.

Comments are closed.