Skip to content

Instantly share code, notes, and snippets.

@lorenzos
Last active February 4, 2022 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzos/e909a88d82c6c6139e5214cbc64daf6c to your computer and use it in GitHub Desktop.
Save lorenzos/e909a88d82c6c6139e5214cbc64daf6c to your computer and use it in GitHub Desktop.
Set Dropbox ignored attribute on files, updates emblems for Thunar
#!/bin/bash
# Requires: sudo apt install attr libglib2.0-bin xdotool
ATTR_IGNORED="com.dropbox.ignored"
ATTR_EMBLEMS="metadata::emblems"
EMBLEM_IGNORED="emblem-colors-red"
function ignore {
attr -s "$ATTR_IGNORED" -V 1 "$1" >/dev/null
}
function restore {
attr -r "$ATTR_IGNORED" "$1" >/dev/null
}
function query {
attr -q -g "$ATTR_IGNORED" "$1" &>/dev/null
ignored=$?
if [[ "$2" == "print" ]]; then
realpath "$1"
if [[ "$ignored" == "0" ]]; then
echo " => is IGNORED in Dropbox"
else
echo " => is NOT ignored in Dropbox"
fi
fi
return $ignored;
}
function emblems {
emblem "$1" "$2" # Self
cd "`dirname "$1"`" # Containing folder
for f in *; do
emblem "$f" "$2"
done
}
function emblem {
query "$1"
if [[ "$?" == "0" ]]; then
gio set -t "stringv" "$1" "$ATTR_EMBLEMS" "$EMBLEM_IGNORED"
if [[ "$2" == "print" ]]; then
realpath "$1"
echo " => emblem SET"
fi
else
gio set -t "unset" "$1" "$ATTR_EMBLEMS"
fi
}
function usage {
echo "Usage: ";
echo " bash `basename $0` [ignore|restore|query] PATH"
echo " bash `basename $0` emblems FOLDER"
exit 2
}
if [[ "$#" -ne 2 ]]; then
usage
else
case $1 in
ignore)
ignore "$2"
emblems "$2"
query "$2" print
exit 0
;;
restore)
restore "$2"
emblems "$2"
query "$2" print
exit 0
;;
query)
query "$2" print
;;
emblems)
emblems "$2" print
exit 0
;;
*)
usage
;;
esac
fi
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<icon>dropbox</icon>
<name>Ignora in Dropbox</name>
<unique-id>1616513445346275-1</unique-id>
<command>bash /home/lorenzo/.dropbox-ignore ignore %f &amp;&amp; xdotool key F5</command>
<description></description>
<patterns>*</patterns>
<directories/>
<audio-files/>
<image-files/>
<other-files/>
<text-files/>
<video-files/>
</action>
<action>
<icon>dropbox</icon>
<name>Ripristina in Dropbox</name>
<unique-id>1616513445346275-2</unique-id>
<command>bash /home/lorenzo/.dropbox-ignore restore %f &amp;&amp; xdotool key F5</command>
<description></description>
<patterns>*</patterns>
<directories/>
<audio-files/>
<image-files/>
<other-files/>
<text-files/>
<video-files/>
</action>
<action>
<icon>dropbox</icon>
<name>Aggiorna emblemi per Dropbox</name>
<unique-id>1616513445346275-3</unique-id>
<command>bash /home/lorenzo/.dropbox-ignore emblems %f &amp;&amp; xdotool key F5</command>
<description></description>
<patterns>*</patterns>
<directories/>
</action>
</actions>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment