From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14770 invoked from network); 29 Mar 1999 07:17:08 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 29 Mar 1999 07:17:08 -0000 Received: (qmail 23755 invoked by alias); 29 Mar 1999 07:16:36 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 2254 Received: (qmail 23748 invoked from network); 29 Mar 1999 07:16:32 -0000 From: "Bart Schaefer" Message-Id: <990328231626.ZM9717@candle.brasslantern.com> Date: Sun, 28 Mar 1999 23:16:26 -0800 In-Reply-To: <19990329133756.A505@tertius.net.au> Comments: In reply to Bek Oberin "Idle function?" (Mar 29, 1:37pm) References: <19990329133756.A505@tertius.net.au> X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-users@sunsite.auc.dk Subject: Re: Idle function? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Mar 29, 1:37pm, Bek Oberin wrote: } Subject: Idle function? } } Is it possible for a console to auto-execute a command What is "a console"? } when it has been idle for x number of minutes? Like Sweth, I remember you asking a similar question some while ago. It was the reverse last time, though, wasn't it? How to do something when the tty had NOT been idle for some length of time? Zsh has the $TTYIDLE variable and $TMOUT ... I personally have this in my init files: # Update title bar periodically if it has been idle a long time (10 min). # Otherwise let precmd() do it, so we don't cause unwanted scroll-to-bot. precmd() { TMOUT=600 ; title } TRAPALRM() { TMOUT=60 ; title } The `title` function puts the current time and current directory on the screen somewhere -- in the status bar if the terminal has one, or in the title bar of an xterm (whence the name), or wherever. Normally this is updated every time a prompt is printed, in precmd(), which is often more than once a minute. If I'm away from my terminal for 10 minutes, however, TMOUT kicks in and the title starts updating every 60 seconds from TRAPALRM. As soon as I get back and start running commands again, the delay goes back to 10 minutes. You'll probably find almost exactly that description in the archives a few previous times, if you look. If you want something that works even when a command (say, an editor) is in the foreground, then you have to do something like background a loop that alternately sleeps for a while and checks $TTYIDLE. Unfortunately, you can't do this with a subshell because TTYIDLE is always -1 in a job backgrounded that way; so something like: zsh -fc "sleep 10; ((TTYIDLE > x * 60)) && echo Do Something 1>&2" That still doesn't get the "topmost" zsh (assuming that's what you mean by "a console") to do anything; it makes itself pretty unreachable when a child process is in the foreground. So you might be just as well off with the TMOUT hack. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com