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

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

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

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

概观

要查找文件夹的元数据,您需要使用命令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 </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" 

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