Ten soubor si musíš napřed vytvořit (umístění ikon do něj uložit) a teprve pak ho můžeš synchronizovat (a umístění ikon obnovit).
Použij tento script (desktop_icons-layout.py):
#!/usr/bin/env python3
import subprocess
import os
import sys
from datetime import datetime
# --- set your localized desktop name below:
dt_name = "Plocha"
# ---
# used strings & definitions
now = datetime.now
val = " 'metadata::nautilus-icon-position' "
search = "gvfs-info -a"+val
set_val = "gvfs-set-attribute -t string "
home = os.environ["HOME"]
dt_dir = home+"/"+dt_name
datafile = home+"/.plocha_nautilus_LAST.txt"
datafile_old = home+"/.plocha_nautilus_bak_{}.txt".format(now().strftime('%Y-%m-%d-%H:%M:%S'))
arg = sys.argv[1]
get = lambda cmd: subprocess.check_output(["/bin/bash", "-c", cmd]).decode("utf-8")
def snapshot():
# backup the previous snapshot
try:
os.rename(datafile, datafile_old)
except FileNotFoundError:
pass
# list the items on the desktop, look up their positions
dt_items = os.listdir(dt_dir)
dt_data = []
for f in [f for f in dt_items if all([not f.startswith("."), not f.endswith("~")])]:
f = '"'+f+'"' if f.count(" ") > 0 else f
file = dt_dir+"/"+f
cmd = search+file
try:
loc = [int(n) for n in get(cmd).split()[-1].split(",")]
# loc[0] = loc[0] - screen_pos[0]; loc[1] = loc[1] - screen_pos[1]
loc = (",").join([str(n) for n in loc])
open(datafile, "a+").write(file+"|||"+loc+"\n")
except:
pass
# notify that a snapshot was taken
subprocess.Popen(["/bin/bash", "-c", "notify-send 'Nautilus icons snapshot was taken'"])
def restore():
# wait for 20 seconds for the desktop to be fully loaded and the screen to be found - pouze pokud používáme skript pro obnovu ikon automaticky po každém přihlášení.
#time.sleep(20)
# read the snapshot file
items = [l.strip().split("|||") for l in open(datafile).readlines()]
for item in items:
try:
xy = [int(n) for n in item[1].split(",")]
move_to = (",").join(str(n) for n in [xy[0], xy[1]])
command = set_val+item[0]+val+move_to
subprocess.Popen(["/bin/bash", "-c", command])
except:
pass
# send notification1 for F5 refresh after icons restore - jen v případě nerestartování nautila.
#subprocess.Popen(["/bin/bash", "-c", "notify-send 'Click on the desktop and press F5'"])
# restart nautilus
subprocess.call(["killall", "nautilus"])
subprocess.Popen(["nautilus", "-n"])
# send notification2 after nautilus restart
subprocess.Popen(["/bin/bash", "-c", "sleep 2; notify-send 'Pozice ikon Nautila byly obnoveny' -t 10000"])
if arg == "snapshot":
snapshot()
elif arg == "restore":
restore()
Který spusíš s parametrem snapshot nebo restore
python3 "/cesta/k/desktop_icons-layout.py" snapshot
python3 "/cesta/k/desktop_icons-layout.py" restore
Ikony se uloží do souboru ~/.plocha_nautilus_bak_datum.txt což si můžeš smozřjmě změnit dle libosti. Tento soubor pak synchronizuj.
Celé to může probíhat automaticky, např. po přihlášení.