Hi there! I'm developing a program that allows the user to open and edit files using both an editor and the terminal. Once the user has finished editing the file an update is sent to the logbook that compares the file before and after it was edited - this can only be done if the file is closed (I think) to guarantee the user is finished editing it. Currently I am checking if the file is closed like this:
while :
do
if pgrep -x "gedit" > /dev/null; then ###**NOT RELIABLE NEED TO CHANGE**###
tput cup 2 5 ; echo -e "${RED} Can not update log until editor is closed! ${NC}"
tput cup 3 5 ; echo -e "${boldon}Please finish editing your file and close gedit/text editor.${boldoff}"
sleep 1
else
clear
updateLog
fi
done
This method does work but it isn't very effective as the if statement checks if ANY file is open in gedit - not the particular one the user has opened which is what I want to do. I played around with PID's and was unable to find a solution.
Is there a better way of doing this?
Thanks in advance,
-cherryTango