Hide Files via Nautilus Right-Click (.hidden file)
Just a quick request: One feature that I really miss is being able to hide folders easily. I know there are cool scripts out there that one can run from a Nautilus right-click menu. Here's my suggestion:
Someone should make a short little script that adds the selected file to the folder's .hidden file, or create a .hidden file if one doesn't exist and then add the name. I would do this myself, but I'm not quite up to par on my bash skills (I wouldn't know how to pull the file name to add it into the .hidden file, and it would take me a while to figure out how to determine if a .hidden file existed yet).
Many thanks!!!
Re: Hide Files via Nautilus Right-Click (.hidden file)
I don't know exactly how you want to do this, but are you thinking of a .hidden directory, and then moving files that you want to hide into it? Or just changing FileName to .FileName to hide it? I could write a script for either, but I can't exactly tell which you want.
Re: Hide Files via Nautilus Right-Click (.hidden file)
You dont need a script to do so. Just select the file, hit F2, and put a . in front.
Re: Hide Files via Nautilus Right-Click (.hidden file)
Right, good thoughts, but not what I was thinking.
In Ubuntu, if one creates a file called ".hidden" and then uses a text editor to add then names of files into the ".hidden" file, those files will be hidden. The advantage of this is that it won't change the path of a file. A use for this is, for example, downloading a web page. You can add the folder with the referenced files to the ".hidden" file, and the index file will still reference them correctly.
In Windows, you can right click on a file to open up its properties and make it hidden. I'm looking for something this easy in Ubuntu, because I think Ubuntu should be better than Windows, and in this case, it's not. Not yet. Adding a "." in front of the file is one option, yes, but it doesn't always work. Adding the filename to the ".hidden" folder seems much more robust to me, but there's no easy or intuitive way to do it. You have to know that it's possible to create a ".hidden" file, create it, and then manually type in (or copy and paste) every file name you want to hide into that file, which gets old. So that's what I'm aiming for.
Right click -> scripts -> hide. Done. That would be nice :)
1 Attachment(s)
Re: Hide Files via Nautilus Right-Click (.hidden file)
Install nautilus-actions using whatever your normal method is (or just click the link)
Save the following code in /home/yourusername/.hidefile.sh or just save the attachment which is the same thing.
Code:
#!/bin/bash
#bash script to be called from nautilus actions
#change to the directory where the file is
cd "$1"
#the filename passed as the argument is added to the .hidden file
echo "$2" >> ./.hidden &&
#simulate the pressing of the F5 key to refresh the window
xte "key F5"
exit
Then make it executable, open terminal then:
Code:
chmod +x ~/.hidefile.sh
Open nautilus actions configuration (system>preferences>nautilus actions configuration) and add a new action with the following:
Quote:
Menu Item And Action
Label: Hide This File
Tooltip: Add file to .hidden so that it is hidden
Icon: usr/share/pixmaps/nautilus/erase.png
Path: /home/YOURUSERNAME/.hidefile.sh
Parameters: %d %f
Conditions
Filenames: *
Mimetypes: */*
Selection Contains: both
Multiple Files: unchecked (no)
Advanced Conditions
Only local files
Restart nautilus by pressing alt-f2 and entering nautilus -q to quite (don't do this if you are currently copying files etc) then open go to places > home or any other location to restart. Alternately you can just logout and back in. Now when you right click on a file or folder there will be a Hide This File option.
Re: Hide Files via Nautilus Right-Click (.hidden file)
ryanhaigh, too much script for a simple action. Open up ~/.gnome2/nautilus-scripts/ and then create a new file with the name of the script you want. Then paste this into it:
Code:
#!/bin/bash
touch $PWD/.hidden
echo "$PWD/$NAUTILUS_SCRIPT_SELECTED_URIS" | tee -a $PWD/.hidden
Much cleaner script and easier to understand what it's doing. Touch creates the file if it doesnt exist. Then the script echoes the name of the file you've right-clicked then appends it to the .hidden file in the directory.
Re: Hide Files via Nautilus Right-Click (.hidden file)
Well, I have to say, this is the best response I've gotten to a feature request ever, and makes me believe in the Ubuntu community again. Thanks guys!
Ryan's script wins in this case, because it actually added the option to my right click menu. That is, "right click -> Hide This File" instead of "right click -> scripts -> Hide this file".
PinkFloyd, I have to give you credit for innovation, but unfortunately I couldn't get your script to work. The problem is that I don't need the path to the file to be copied, just the file name. Should be a simple fix. And to be fair, your solution was what I asked for. Ryan just went above and beyond the call of duty.
The only thing is that Ryan's method takes a little elbow grease on the user end to get it working, but not much, and the result is very pretty.
So to recap, I'm just thrilled that I got two answers to this question, and that I have a really good way to easily hide files, a functionality that I've honestly been missing since Feisty. Thanks!!!
Re: Hide Files via Nautilus Right-Click (.hidden file)
Hmm, I didn't know about the .hidden file! You learn something new every day =) I'll definitely be putting this to good use!
Re: Hide Files via Nautilus Right-Click (.hidden file)
Just take out the $PWD part then. If you want it as an action, just follow what ryan posted about adding to Nautilus Actions and put the path to my script.
Re: Hide Files via Nautilus Right-Click (.hidden file)
PinkFloyd, thanks for the tip but I did know about nautilus scripts, I just prefer nautilus actions from a usability point of view. What I would like to know though is why using echo for the command with %f >> .hidden doesn't work.
EDIT: I might give it a try using tee instead.
Later on I might revise this script/action so that it can be used with multiple files, unfortunately I'm not as proficient with bash as I once was, but I'll try with my new favorite language python.