InsideDarkWeb.com

Can one see from other program if Gedit is running and contains unsaved text?

I use Gedit as my favourite text editor. Is it possible to write a script for example in Python or Bash to check if Gedit is running and contains unsaved text?

Unix & Linux Asked on November 21, 2021

1 Answers

One Answer

Gedit is running

pidof gedit should give you the answer

contains unsaved text

As far as I know Gedit doesn't support any DBus interface which makes this task relatively difficult but possible:

#! /bin/bash

for i in `pidof gedit`; do
    for j in `xdotool search --name --onlyvisible --pid $i`; do
        title=`xdotool getwindowname $j`
        case $title in
            **)
                echo "Found running Gedit with unsaved data"
            ;;
            *)
                echo "Gedit is open but there are no unsaved documents"
            ;;
        esac
    done
done

What this script does. It iterates over all found gedit processes, finds their visible windows, iterates over their titles and checks if the title contains * as the first character which indicates an unsaved document.

Bash/shell purists will probably want to replace `` with $( ).

Answered by Artem S. Tashkinov on November 21, 2021

Add your own answers!

Related Questions

Authentication fails though the password is correct

0  Asked on September 3, 2020 by rohit-pillai

     

Cant’t load Windows 10 anymore

1  Asked on August 31, 2020 by j-doe

       

Change order a icons in system tray widget in KDE?

1  Asked on August 29, 2020 by paddy

 

rts5139/rtsx_usb borked in 3.15+

2  Asked on August 27, 2020 by roman

     

ETH0 no address ip with ifconfig

1  Asked on August 24, 2020 by akame14

     

Kali Linux 2020.2 Wifi Not Working (Realtek)

0  Asked on August 18, 2020 by harriet

     

Base64 encoded ignition file gets messed up

1  Asked on August 15, 2020 by michael-stbich

     

Weird textures on KDE Plasma 5.0

0  Asked on August 11, 2020 by rushisrinivas-k

     

How do I syntax check a Zsh script?

1  Asked on August 9, 2020 by akhil-jalagam

     

How can I swap my two screens, left to right?

5  Asked on August 4, 2020 by ripper234

         

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.