atchange, which stands for "At Change", is a Perl (CPAN) script that runs in a window and watches a single file or a set of files. When any of the files change, atchange performs whatever you would like it to do.
For example, if you are editing a program, atchange
can compile (or 'make') the program when you write it to disk.
In one window (set to a particular directory) I would type:
atchange hello.c "cc hello"In another window I would edit hello.c. Whenever I save the program, it will automatically be compiled. There will be about a 1 second delay since that is the resolution that atchange looks at the file. (As described in the technical paper, this can be changed. Currently this information is at How can I sleep() or alarm() for under a second?.
Actually, atchange only watches the modification date of the file, so if you just do a unix touch, it will wake up. This could be used to trigger a series of responses.
In the ancient but venerable (and still highly useful) Unix editor vi, one normally saves a program with the command ":w[cr]". However, if you add the line
map , :w^Mto your ~/.exrc file (~/.vimrc for Vi Improved, vim), then a single "," will write the file out, saving even more time. ([cr] means "carriage return" key that you type and "^M" is control M that must be in the .exrc file. To create a control M in vi, type control-v followed by control-m.)
If I want to do several things at once, I type them on one line:
atchange hello.c "cc hello; hello"This would first compile and then run the hello program. (The semicolon ";" separates commands in Unix.) This could also be put into a file, I often name it "automate":
hello.c cc hello helloThen atchange is started in its own window with:
atchange automateOne can have several compilations in the automate file:
hello.c cc hello hello bello.c cc bello belloThey MUST be separated by a blank line, to tell atchange to treat them separately. NO SPACES ARE ALLOWED ON THE BLANK LINE!!! If you use spaces the item will become part of the previous item and executed along with that. You can use the rembla.p program to remove the extra blanks. You could also use the Unix version that works with pipes: rb.p.
My use for the atchange script is to compile latex documents and run xdvi to visualize them. Using a file such as the following:New as of 2010 July 01 in atchange version 2.10.figures/*.* rubber -d -Wall amsart.tex *.tex rubber -d -Wall amsart.tex amsart.pdf xdvi -remote latex_preview -reloadRubber is a nice python tool that automates the process of running latex, bibtex, +dvipdf, etc. much in the same way as latexmk. http://www.pps.jussieu.fr/~beffara/soft/rubber/
It's even more fun to have a program compile, run to make a PostScript file, and then to pop that up with ghostview! One can immediately see the function of the program without lots of mousing around. Here's one way:
hello.c cc hello hello > graphic.ps ghostview graphic.psWhen you decide to test the hello.c program, touch the "," key and sit back. Three steps occur sequentially: the hello program is compiled, hello writes some postscript graphics into a file (graphic.ps) and then ghostview shows the file. Now if you've arranged the windows just-so, the display will appear over the editor window. All you need to type is "q" to destroy the ghostview, and you then fall right back to the editor for another round.
Doing the same thing in several atchange stages has some advantages:
hello.c cc hello hello hello > graphic.ps graphic.ps ghostview graphic.ps parameters helloOne has two windows in vi, one on hello.c and the other on a parameter file that controls how hello will run. Then one can switch between the two editors with a single key stroke (on a Sun workstation, the "Front" key does that). When either the program or the paramter file change, the graphic appears.
The big selling point for WYSIWYG (it stands for What You Want Is Not What You Get ;-) is the immediate text feedback. But the price you pay is that the file formats are unreadable. This means that if the company ever goes out of business, you will have a tough time converting to another format.
In contrast, typesetting languages such as LaTeX store the text in pure ASCII. This means that they can always be edited in the future (an example is the technical paper for atchange which started out in ASCII in the older troff typesetting language. It was easy to convert it to HTML, yet another typesetting language.) Also, it means that it's easy to write programs that create documents or modify them.
LaTeX does a FANTASTIC job at mathematical and scientific notation. An example is the Information Theory Primer.
If you are editing a LaTeX document, atchange can typeset your document and display the current version using xdvi As computers become faster, this approaches a WYSIWYG. Now LaTeX completely beats word processors! (As if there was ever any comparison.)
Just the other day I was writing a LaTeX document in one window, with atchange typesetting it in another window and atchange telling me the current length of the abstract in a third window.
With more than one page of text, one would like to keep the viewer on one page and "tickle" it to update.
Here my trick for getting xdvi to update its display of a page automatically. I use several scripts:
The l script now writes the $paper.lin file. setxdvi is available from our archive. Note: your xdvi must be reasonably modern to use this. As I don't have a modern xdvi on my main computer yet, not all of these scripts are fully developed.set paperline = `cat $paper.lin` if `echo $paperline | grep '-'` != '' then echo setxdvi $paper.dvi -$paperline setxdvi $paper.dvi -$paperline else echo setxdvi $paper.dvi $paperline setxdvi $paper.dvi $paperline endif
On 1997 Jan 13, Stephen Eglen (firstname.lastname@example.org) wrote to me:
I notice one of your applications of atchange is for Latex. This is a good solution. I was just wondering if you had seen another solution: that provided by emacs. Not only can it can do similar things to what you show here, but the big advantage I find is that you can get it to just run latex on a region rather than the whole file or collection of files that you are editing. Rather than wait for latex to run through a thirty page doc, it can just be run on the couple of paras that Im interested on at the moment, cutting down even more on the delay between editing and seeing what the result is.
Furthermore, if you are using a lot of maths in your docs, you can get it to display most of the maths symbols in the editor window as you type. (But I don't use this aspect.)
But if you don't emacs (or don't like using it) then no worries!
Thanks for the tip!
... Five years later, on 2002 Oct 19 Stephen wrote again to tell about this:
I recently found the program, latexmk, which is a kind of specialised version of atchange for running latex. The nice thing is though that it only runs latex, bibtex, as many times as needed to make sure your document is correct. It can also then send a signal to xdvi to update itself -- makes latex editing nice and fast for short documents! Plus, of course, the link with atchange is that it watches your latex file for changes (using the -pvc switch). The original source of latexmk, by John Collins, is at http://www.phys.psu.edu/~collins/software/latexmk-jcc/. However, the official copy is at CTAN: http://www.ctan.org/tex-archive/support/latexmk/
Thanks for another great tip!
To make latexmk work with the xpdf viewer (on a Mac OSX for example), include in a ~/.latexmkrc file these contents:
Then LaTeX will run and the PDF will be updated when you write your file(s) out.$pdf_previewer = "start xpdf -remote %R %O %S"; $pdf_update_method = 4; $pdf_update_command = "xpdf -remote %R -reload";
eh myfilename.htmleh will point Netscape to 'myfilename.html' and then run your editor (vi by default) on 'myfilename.html'. If myfilename.html does not exist, eh will create a small starter html for you. eh is written in Standard shell (e.g., bash or ksh), so you have to have one to make it work.
If you type
eh -longit will give longer instructions.
Jeffreys Copeland and Haemer describe this program in their paper, "We Use vi to Edit Web Pages: How to turn vi into a WYSIWYG HTML editor".
The program medlinebib will convert from Medline bibliography format to BiBTeX. Atchange can be used to automate the process. (New as of 1999 September 3)
To set up atchange, first make sure the atchange script is in your execution path. Then just run it as in the examples given on this page. Unix reads the first line of the Perl code and will automatically start. There is no need to 'compile' the code.
If atchange does not work and you get this message:
stty: standard input: Invalid argument
then you need to do the following.
The problem is that atchange launches a csh, but if you have a .csh that calls stty this will cause trouble for stty. In the current version of atchange is some code that sets an environmental variable called PERLCSH. This allows the .cshrc to know that atchange has called it. To tell your .cshrc not to execute the stty when called from atchange, you need to add two lines to your code:
if ( (! $?PERLCSH ) && $?prompt) then stty erase '^H' set prompt = "`uname -n` \!% " endifThe top and bottom (blue) lines test whether the .cshrc is being called from perl and if it is an interactive shell. If so, the stty and set prompt are called. You may have other lines in between these two, but the important thing is that the two lines surround the stty call. (Thanks to James W. Haefner (Department of Biology, Utah State University, Logan, UT, email@example.com) for the tip!
Atchange could use a slight tweek to run more smoothly under Linux. We will absorb this problem into the code when we have a general solution.
The problem is that under some operating situations, atchange will give this message:
stty: standard input: Invalid argumentHowever atchange seems to function fine anyway. We have eliminated this effect from Solaris but it still appears under Linux. A "correction" for Linux is noted in a comment in the current version of atchange. Here is some more information about what is happening:
I have the Redhat 6.0 distribution and am using bash. SHELL is defined as "/bin/bash" and redhat has apparently linked "/bin/sh" to "/bin/bash". With the perl code as originally written $shell gets set to "/bin/bash" (as expected) and (apparently) ".cshrc" is not opened inside the perl script. I removed my fix and still get the error. Since you mentioned errors, I further changed atchange to test if the current shell is bash. if true, then $shell is set to "/bin/sh", if false, the original in-line conditional is used to set $shell. It works now, but I can't claim to fully understand why because of the link between "/bin/sh" and "/bin/bash".You will have no problems if you leave the code alone and just put up with the message until we have learned how to eliminate it.James W. Haefner Department of Biology Email: firstname.lastname@example.org Utah State University Voice: 435-797-3553 Logan, UT 84322-5305 Fax: 435-797-1575
Of course nothing (other than silly non-multitasking operating systems) prevents you from having many atchange programs running at the same time in different windows all doing different complex things and all set up "on the fly" as you need them.
There are many other uses of the program. It allows one to "automate" many things one does. Rather than mouse and type repeatedly, atchange allows one to concentrate on the job at hand.
atchanges : utilities using the atchange command
Usage: atchanges [-s|-p] option [file | extension] ...
atchanges help: print this message
atchanges show: print a list of currently running atchange processes,
with PID and arguments.
atchanges kill: print list as above, then kill all of those processes
(after a brief pause to let you interrupt). Then runs start.
atchanges start: run atchange to start up all files named in the environment
(The previous version is now kept at atchanges.1997may27.)
Also, you might want to check out webrowse(1) -- a generalized, enhanced and simplified front-end for things like "netscape -remote ...". Can be really handy in conjunction with atchange(1).
|---------| | a = 0 --| | b = 1 --| | c = 1 --| a+b | d = 0 --| a*b | e = 1 --| ~d |---------|
Atchange will run on on Mac OS X if you set the location of perl. To determine this type in a terminal:
which perlIt should come back with
/usr/bin/perlThe first line of Atchange is
#!/usr/local/bin/perlso just change it to
#!/usr/bin/perlPut the revised atchange in your path and it should work immediately. ALTERNATIVELY, just grab this version:
Example I made a postscript program on my mac and automated the process. So while I edited the file cir.ps, I used convert (from the ImageMagick package) to make a gif and the system Preview to view it. But of course it switches to the Previewer, which meant I had to mouse all the time. But it turns out that one can force the re-opening of the terminal and keep one's fingers on the keyboard! This is an automate script:
cir.ps clear echo starting conversion convert cir.ps cir.gif open cir.gif open -a Terminal echo done dateThe Preview updates to the new image AND Terminal opens again and I'm still in vi working on the file. One can also convert to pdf (using ps2pdf) but unfortunately the Adobe Reader isn't smart enough to update when the file changes. However, see above on this page for how to use the Skim PDF Viewer instead.
This page is https://alum.mit.edu/www/toms/atchange.html
origin: 1997 January 1
updated: 2017 Mar 06: replace broken link to http://www.perl.com/pub/v/faqs