I will have to check for other releases, but on 14.04 and 15.10, the gsettings
command to check visibility of hidden files is:
gsettings get org.gtk.Settings.FileChooser show-hidden
To set the value to false
(don't show hidden files):
gsettings set org.gtk.Settings.FileChooser show-hidden false
or true
:
gsettings set org.gtk.Settings.FileChooser show-hidden true
1. A script to (re) set the value then is:
#!/usr/bin/env python3
import subprocess
import sys
import time
interval = int(sys.argv[1])
key = "org.gtk.Settings.FileChooser"
val = "show-hidden"
while True:
time.sleep(interval)
subprocess.Popen(["gsettings", "set", key, val, "false"])
To run it:
- copy the script into an empty file, save it as
reset_hidden.py
run it by the command:
python3 /path/to/reset_hidden.py <interval>
where the time- interval is in seconds, e.g.
python3 /path/to/reset_hidden.py 600
Add it to Startup Applications
To add it to Startup Applications: Dash > Startup Applications > Add. Add the command:
python3 /path/to/reset_hidden.py <interval>
2. Run the command from cron
If you prefer running the command from cron instead of a background script, an important environment variable is not set:
DBUS_SESSION_BUS_ADDRESS
editing/setting gsettings from cron only works if you first set the variable.
If you'd like to run it from cron, make cron run the script below:
#!/bin/bash
PID=$(pgrep gnome-session)
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
gsettings set org.gtk.Settings.FileChooser show-hidden false
3. More elegantly, using idle time
If you are working on your computer, you probably wouldn't like to have the files hide unexpectedly while working.
Using the script below, files will be hidden after an arbitrary idle time. The setup is exactly like [1]
but the <interval>
time is now the <idle_time>
(in seconds), before the files should hide (again).
The script needs xprintidle
:
sudo apt-get install xprintidle
The script
#!/usr/bin/env python3
import subprocess
import sys
import time
interval = int(sys.argv[1])
key = "org.gtk.Settings.FileChooser"
val = "show-hidden"
idle1 = 0
while True:
time.sleep(2)
idle2 = int(subprocess.check_output(["xprintidle"]).decode("utf-8").strip())/1000
if all([idle1 <= interval, idle2 >= interval]):
subprocess.Popen(["gsettings", "set", key, val, "false"])
idle1 = idle2