title: Running emacs from the command line and handling locked files
body: <p>I'm using org-mode and am looking to export my agenda (<a href="http://members.optusnet.com.au/~charles57/GTD/daily_plan.png" rel="nofollow">example of an agenda</a>) to a text file so that I can display it with conky. The <a href="http://orgmode.org/manual/Extracting-agenda-information.html#Extracting-agenda-information" rel="nofollow">org-mode manual</a> features this command line example to do this:</p>
  
  <pre><code>emacs -batch -l ~/.emacs -eval '(org-batch-agenda "t")' | lpr
  </code></pre>
  
  <p>I've modified this like so:</p>
  
  <pre><code>emacs -batch -l ~/.emacs -eval '(org-batch-agenda "e")' \
  &gt; ~/org/aux/agenda-export.txt
  </code></pre>
  
  <p>I have this set as a cron job to run every 5 minutes. It works great unless I actually have emacs open. Then I noticed that the file <code>agenda-export.txt</code> was empty. In running this manually from the coammand line vs. through cron, I get this error (or similar depending on the files I have open):</p>
  
  <pre><code>...~/org/file.org locked by jwhendy (pid 10935): (s, q, p, ?)?
  </code></pre>
  
  <p>I was going to write a script to perhaps export to <code>agenda-export-test.txt</code>, then perhaps check for an empty file or no lines (<code>wc -l == 0</code> maybe?). If true, leave the existing file alone and delete <code>agenda-export-test.txt</code>. If not, then move <code>agenda-export-test.txt</code> to <code>agenda-export.txt</code>.</p>
  
  <p>But... when I try to run such a script, I'm met with the same emacs inquiry about whether to steal the lock, proceed, or quit. I'm fine with proceeding, as I don't think org-agenda does anything to the files and thus it wouldn't harm anything... but I don't know how to tell emacs to "force" or choose "proceed" if problems are encountered. I need something non-interactive.</p>
  
  <p>So, to summarize, my thoughts were to try:</p>
  
  <ul>
  <li>passing a --force option or similar to emacs to make it proceed at the pause</li>
  <li>see if the exported tmp file has any lines and deal with it accordingly</li>
  <li>tell emacs to run in "read only mode" (but I don't think it exists)</li>
  </ul>
  
  <p>The main issue is that with cron, I'm not there to tell the process what to do, and so it just just make an empty file as the exported results. How can I handle this locked file business with a "blind" process like cron that can't respond?</p>
  
  <p>I've tried asking the mailing list as well without a working outcome. [1] I wondered if someone here might have ideas.</p>
  
  <p>[1] <a href="http://www.mail-archive.com/emacs-orgmode@gnu.org/msg45056.html" rel="nofollow">http://www.mail-archive.com/emacs-orgmode@gnu.org/msg45056.html</a>  </p>