Visão geral
Para encontrar os metadados para uma pasta, você precisa usar o comando gvfs-info foldername
por exemplo gvfs-info /home/homefolder/Desktop
Na lista que retorna, você verá o atributo metadata::nautilus-default-view
que descreve a exibição padrão.
Você pode alterar este atributo usando o comando gvfs-set_attribute foldername attribute newvalue
por exemplo:
gvfs-set-attribute /home/homefolder/Desktop "metadata::nautilus-default-view" "OAFIID:Nautilus_File_Manager_Icon_View"
Roteiro
Agora eu tenho que admitir que minhas habilidades de script bash não são as melhores, mas aqui está - meu script abaixo permitirá que você redefina todas as visualizações abaixo do nome da pasta fornecido.
Sintaxe:
folderreset [OPTION] full_base_directory_name
por exemplo, isso será redefinido para compactar a visualização de todas as pastas abaixo /home/homefolder/Desktop
folderreset -c /home/homefolder/Desktop
use folderreset -h
para a sintaxe.
Sinta-se livre para mexer e alterar.
#!/bin/bash
#Licensed under the standard MIT license:
#Copyright 2013 fossfreedom.
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
################################ USAGE #######################################
usage=$(
cat <<EOF
Usage:
$0 [OPTION] base_full_directory_name
-h, --help display this help
-l, --list set to list view
-i, --icon set to icon view
-c, --compact set to compact view
for example
$0 -i /home/myhome/Desktop
This will reset all directories BELOW /home/myhome/Desktop
EOF
)
########################### OPTIONS PARSING #################################
#parse options
TMP=`getopt --name=$0 -a --longoptions=list,icon,compact,help -o l,i,c,h -- $@`
if [[ $? == 1 ]]
then
echo
echo "$usage"
exit
fi
eval set -- $TMP
#default values
META=OAFIID:Nautilus_File_Manager_List_View
until [[ $1 == -- ]]; do
case $1 in
-l|--list)
META=OAFIID:Nautilus_File_Manager_List_View
;;
-i|--icon)
META=OAFIID:Nautilus_File_Manager_Icon_View
;;
-c|--compact)
META=OAFIID:Nautilus_File_Manager_Compact_View
;;
-h|--help)
echo "$usage"
exit
;;
esac
shift # move the arg list to the next option or '--'
done
shift # remove the '--', now $1 positioned at first argument if any
if [ ! -d "$1" ]
then
echo "Directory does not exist!"
exit 4
fi
find "$1"/* -type d | while read "D"; do gvfs-set-attribute "$D" "metadata::nautilus-default-view" "$META" &>/dev/null; done
Wrapper da GUI
Aqui está um script de wrapper da GUI simples que pode ser usado para definir o modo de visualização diretamente no menu de contexto dos scripts do Nautilus:
#!/bin/bash
# Licensed under the standard MIT license
# (c) 2013 Glutanimate (http://askubuntu.com/users/81372/)
FOLDERRESET="./folderreset.sh"
WMICON=nautilus
THUMBICON=nautilus
WMCLASS="folderviewsetter"
TITLE="Set folder view"
DIR="$1"
checkifdir(){
if [[ -d "$DIR" ]]
then
echo "$DIR is a directory"
else
yad --title="$TITLE" \
--image=dialog-error \
--window-icon=dialog-error \
--class="$WMCLASS" \
--text="Error: no directory selected." \
--button="Ok":0
exit
fi
}
setviewtype (){
VIEWTYPE=$(yad \
--width 300 --entry --title "$TITLE" \
--image=nautilus \
--button="ok:2" --button="cancel" \
--text "Select view mode:" \
--entry-text \
"list" "icon" "compact")
if [ -z "$VIEWTYPE" ]
then
exit
fi
}
checkifdir
setviewtype
"$FOLDERRESET" --"$VIEWTYPE" "$DIR"
O script depende do fork do zenity yad
que pode ser instalado a partir deste PPA . Certifique-se de apontar FOLDERRESET=
para o local do folderreset
script em seu sistema.
metadata::nautilus-default-view
:(