Extracting Nautilus / gvfs notes for files
Posted: January 18, 2011 Filed under: Uncategorized 11 Comments »Being able to add notes to any file in Nautilus of the Gnome desktop is such a wonderful thing. But. The implementation is poor to say the least. The notes are not embedded into the file as one might think, like it is normally done with the JPEG files, neither Linux file system extended attributes are used. You can _not_ back the files up in archive without losing the notes, neither you can copy them to an external storage, nor you can even freely move the files around in the same logical disk. You lose notes added to documents if you move them from one user account to another. There is _no warning_.
This sucks.
Even more, rumour says it that the notes feature instead of refining it will be dropped completely soon, but let us wait and see.
Anyway. The good thing is that you _can_ extract the notes from the gvfs virtual file system information and save them in separate text files, if you wish.
Actually the notes are embedded in the constantly changing (?) files which you can find in ~/.local/share/gvfs-metadata (in Ubuntu 10.10). Look for the files which have in their name the name of the location where your files with the notes are/were located.
Even better, if you have moved some files by accident and your so valued notes are not there any more, don’t panic! They still might be inside the aforementioned files in the gvfs-metadata directory. You also may try moving your files back to their previous location. Very likely that your notes will spring back to life and appear attached to the files again.
Now, here is a simple script assembled from various parts found on Internet, which traverses all the subdirectories of the given directory, looks for information on notes for the particular file in the Nautilus user specific information, extracts it if any and saves it into the text files with the same name, adding a custom extension of *.ntxt (just so that it is easier to distinguish it from other files).
Grab this text, paste it into a new text file, add execution rights for it, then run it from command line and tell it which directory to process:
#!/bin/bash
process_dir() {
local -a subdirs=()
echo "Scanning directory: $1"
# Scan the directory, processing files and collecting subdirs
for file in "$1"/*; do
if [[ -f "$file" ]]; then
echo "Processing file: $file"
# actually deal with the file here...
#gvfs-info $file | grep annotation | sed s/' metadata::annotation: '/''/g > $file.note
note=$(gvfs-info "$file" | grep annotation | sed s/' metadata::annotation: '/''/g)
#len=`echo ${#note}`
#echo $len
if [ -z "$note" ]
then
echo "No note for file $file"
else
echo "Found a note for file \"$file\", saying: \"$note\""
echo "$note" > $file.ntext
fi # $String is null.
elif [[ -d "$file" ]]; then
subdirs+=("$file")
# If you don't care about processing all files before subfolders, just do:
# process_dir "$file"
fi
done
# Now go through the subdirs
for d in "${subdirs[@]}"; do
process_dir "$d"
done
}
clear
if [[ -z "$1" ]]; then
read -p "Please enter a directory for me to scan " dir
else
dir="$1"
fi
process_dir "$dir"
Thank you very, very much for this nice little script!
I am migrating from Ubuntu to Kubuntu and thought I would lose all the notes I created for my podcast-collection which took me the 4 years to setup!
Hey! This is nice to hear! Glad it helped!
It’s your week
Thank you very much ; I was somehow in the same situation as dowel, except it’s disappeared from any gnome3…and also 4 years of image collecting.
Feeling muuuuuuuuuuuuch better
Thanks! I am happy to hear it saved your day.
Sympathise with you – don’t know why they insisted on “fixing” something that wasn’t broken. I’ve used the Notes tab for over two years, and so a lot of information about the settings, places, associated facts about my images is now not available ’cause of this – I’d swear if I could get away with it. LOL.
Exactly!
Another annoying thing is the use extended attributes. Or more precisely – lack of that use.
This might be a better alternative to Gnome notes… if it would ever be implemented decently.
Thank you for the helpful script. I am rather new to BASH.
Line 21 was changed to echo “$note” > “$file”.ntext to accommodate spaces in file names.
A little problem is that the script only recognizes the first line of text in the Note tab. The script ignores any text beyond the first LINEFEED.
Any suggestions?
Hey, man! You are welcome!
I am too lazy at the moment to look into this issue…
But thanks for pointing it out!
To recognize multiple lines of text with one or more LINEFEEDS in the Note tab. Change line 15 to:
note=$(gvfs-info -a metadata::annotation “$file” | sed -e ’1 s/attributes://’ | sed -e ’1N;s/\n //’ | sed -e ‘s/ metadata::annotation: //’ )
No global switches were used for the sed searches in order to select only the first instance of each search-term. Thanks again _crcok_ for the super-useful script.
Great! Well done!
Thanks! That will come in useful!
In Gardener’s script amendment of 05mar2013 think the last sed should be:-
sed -e ’1 s/ metadata::annotation: //’
many thanks to all