Pages

Wednesday, November 14, 2012

How to Create Empty File (Add Contextual Menu) with Terminal on Nautilus 3.6



To create an empty file there are at least two ways: use the terminal – and the touch command – or open a text file and save it, without content, in the position we want. Up to 3.4 Nautilus was also possible to create a new file via the context menu: enough to give a right click on an empty spot in the current directory / the desktop and select Create New > Blank Document . Too bad this feature has been eliminated in Nautilus 3.6.
So how to regain – in Nautilus 3.6 – the same functionality without using tricks complicated? The methods are two, both valid, and expose them there below.

Method 1 – Create an extension for Nautilus 3.6

This is a very simple method , is to add a ‘ extension in Python for Nautilus 3.6 which is really to change the context menu : via terminal we first create the folder that will contain script , and immediately after, we will create the script itself. Translated into commands that corresponds to
mkdir-p ~ / .local / share / nautilus-python / extensions
gedit ~ / .local / share / nautilus-python / extensions / nautilus-acme.py

Clearly we can replace gedit with our favorite text editor. Inside the new file open, now, let’s write the following:
from os.path import join from
gi.repository import GObject, Nautilus

 class Acme (GObject.GObject, Nautilus.MenuProvider):
def __ init__ (self): pass

final new_empty_file (self, menu, folder):
with open (join (folder.get_uri (). replace ("file :/ /", ""), "new_file"), 'w') as f: f.write
('')
return
final get_background_items (self, window, CURRENT_FOLDER):
AcmeMenuItem = Nautilus.MenuItem (
name = "Acme :: NewEmptyFile"
label = "Create empty file "
tip =" Create a new empty file "
)

AcmeMenuItem.connect ('activate', self.new_empty_file, CURRENT_FOLDER)
return [AcmeMenuItem]

Save the file and restart Nautilus, with the command
nautilus-q
Done! Now, clicking the right mouse button on a blank part of our desk / a Nautilus window, we will directly support the “Create empty file.”

Method 2 – Use templates

This method is even easier: simply create an empty file in the folder ~ / Templates for always have it available. Then open a terminal and type
touch ~ Templates / File_Vuoto
after that restart Nautilus 3.6, with the command
nautilus-q
Done! We can now create a new empty file with the context menu of Nautilus, through Right click> Create Document> File_Vuoto.
thanks to webupd8 & askubuntu4c940  p 89EKCgBk8MZdE How to Create Empty File (Add Contextual Menu) with Terminal on Nautilus 3.6

No comments:

Post a Comment