如何递归设置目录树的Nautilus视图模式?


11

Nautilus 3.4允许您设置默认的查看模式。它还会记住您对特定文件夹的自定义视图设置。

我希望能够做的是为特定目录树中的所有目录和子目录定义一种查看模式。遍历每个文件夹以手动更改查看模式将花费太长时间。

有什么办法可以做到吗?也许通过修改gvfs-metadata的Nautilus脚本?

Answers:


10

总览

要查找文件夹的元数据,您需要使用以下命令 gvfs-info foldername

例如 gvfs-info /home/homefolder/Desktop

在返回的列表中,您将看到metadata::nautilus-default-view描述默认视图的属性。

您可以使用以下命令更改此属性 gvfs-set_attribute foldername attribute newvalue

例如:

gvfs-set-attribute /home/homefolder/Desktop "metadata::nautilus-default-view" "OAFIID:Nautilus_File_Manager_Icon_View"

脚本

现在,我不得不承认我的bash脚本编写技能不是最好的,但是您可以使用-下面的脚本将允许您重置给定文件夹名称下的所有视图。

句法:

folderreset [OPTION] full_base_directory_name

例如,这将重置为紧凑视图,下面的所有文件夹 /home/homefolder/Desktop

folderreset -c /home/homefolder/Desktop

使用folderreset -h的语法。

随意修改和修改。


#!/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

GUI包装器

这是一个简单的GUI包装器脚本,可用于直接从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"

该脚本取决于yad可以从此PPA安装的zenity fork 。确保指向脚本在系统上FOLDERRESET=的位置folderreset


我使用Nautilus 3.6.3(Ubuntu 13.04),没有这样的属性metadata::nautilus-default-view:(
RaduRădeanu13年

1
@RaduRădeanu-是的Gnome-Devs在v3.6中从nautilus中删除了很多东西:/
fossfreedom
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.