The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 648β€…    Votes:  3β€…
Tags: nautilus   automation  
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

Title: How can I automatically relaunch nautilus if I quit the program?
ID: /2019/10/13/How-can-I-automatically-relaunch-nautilus-if-I-quit-the-program_
Created: October 13, 2019    Edited:  June 12, 2020
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false

Update: October 16, 2019.

Thanks to gnome expert’s answer on linked question below, a faster more stable method of relaunching Nautilus File Manager has been implemented.

This turned out to be a challenging problem because Nautilus is always running to control the desktop. If you kill the program nautilus all your desktop icons will disappear. When nautilus is running and your desktop icons are present and you type nautilus in the terminal then the Nautilus File Manager appears.

Copy this script to a file called ~/ttlus:


# NAME: ttlus (Twenty Thousand Loops Under Startup)
# PATH: $HOME/askubuntu/
# DESC: Answer for:
#       Call Nautilus, named after Twenty Thousand Leagues Under the Sea novel,
#       20,000 times in loop from Startup Applications
# DATE: October 10, 2019.  Modified October 16, 2019.

# NOTE: Things that don't work:

# UPDT: Rpelace loop with occassional focus grabbing and unpredictable delays:
#    while ps -L -p "$PID" -o pid,nice,lwp,comm | grep pool > /dev/null ; do
#       with:
#    while gdbus introspect --session --dest org.gnome.Nautilus \ ... 3 lines

#Program="/usr/bin/nautilus --gapplication-service"
PID=$(pgrep nautilus)

if [[ $PID == "" ]] ; then
    notify-send "ERROR in $0: Cannot find nautilus PID"

for (( l=0; l<LoopLimit; l++ )) ; do
    # Is nautilus file manager running? 1 Window only is desktop icons
    while gdbus introspect --session --dest org.gnome.Nautilus \
        --object-path /org/gnome/Nautilus --recurse | \
        grep -q '^ *node /org/gnome/Nautilus/window/' | \
        grep -v '/window/1' ; do
            sleep "$Sec"
    "$Program" "$HOME" 2> /dev/null
    sleep $(( Sec / 2 ))

notify-send "ERROR in $0: $Program exceeded $LoopLimit loop limit"

Make it executable with chmod a+x ~/ttlus

First test is by typing ~/ttlus & in the terminal. After you are satisfied add it in Startup Applications.

If program runs amok use:

``` bash $ pgrep ttlus 7970

$ kill 7970 1+ Terminated ttlus



⇧ The computer didn't automatically boot from USB, Ubuntu Server 16.04 unusual crontab entry  β‡©