3

I use the Geany IDE for programming, and it does not reliably reload my previously open files, for example after a power outage. I found that Geany has a command line feature which returns a list of all open files in the editor, so I hoped that I could quickly write a cron command that would automatically save that list every hour or so.

I currently have this line in my crontab:

0 * * * * ~/bin/save_geany_files

and the script contains just one line:

geany --list-documents > ~/geany_files.txt

This does not work. I noticed that Geany's --list-documents feature must be called by the same user (I think), so I tried adding "su - [myusername]" to the script, but apparently su cannot be used from within a cron job? So, I am at a loss for how to automate this. I am open to any other solutions to my problem, although Geany options/plugins seem to be unreliable (which is why I tried this in the first place)

monguin
  • 601
  • 1
  • 7
  • 9

1 Answers1

3

By running the crontab like this:

0 * * * * ~/bin/save_geany_files 2> /tmp/geanyerror.log

I found this error message in /tmp/geanyerror.log:

Geany: cannot open display

I solved this by adding the following line to .bashrc:

xhost local:arune > /dev/null

(where arune is my username) and changing my crontab to

0 * * * * export DISPLAY=:0.0 && ~/bin/save_geany_files 2> /tmp/geanyerror.log

My own save_geany_files-script looks like this:

#!/bin/bash
cp /home/arune/geany/savenew.txt /home/arune/geany/saveold.txt
/usr/bin/geany --list-documents > /home/arune/geany/savenew.txt

to store a "backup" for one hour extra.