Nautilus actions, right click execute script: Difference between revisions

From WickyWiki
m 5 revisions
 
No edit summary
 
Line 1: Line 1:
[[Category:Ubuntu]]
[[Category:Ubuntu]]
[[Category:Ubuntu Gnome]]
[[Category:Ubuntu Gnome]]
[[Category:201201]]
[[Category:201809]]
== Install Nautilus Actions ==


Install nautilus Actions GUI to customize Nautilus right click menu:
Add 'Scripts' option to Nautilus. After adding this script you can right-click, go to 'Scripts' and then 'exec'.


<syntaxhighlight lang=bash>
You can then disable the Nautilus script-dialog for executable files and pick your text editor as the default application. This dialog is especially annoying for NTFS drives where every text file is considered executable.
sudo apt-get install nautilus-actions
</syntaxhighlight>


You can export/import your custom items to backup/restore them.
= Configure =


== Nautilus action 'Execute script' ==
Create the 'Scripts' directory, sub-folders are also possible and will appear as sub-menu-items:


Start Nautilus Actions and:
<syntaxhighlight lang=bash>
mkdir -p ~/.local/share/nautilus/scripts/
</syntaxhighlight>


# Define a new action
Create the script file, the filename is what will be used in the right-click menu. The script will run in a separate terminal window. It will also work for multiple scripts, one at the time, after each other:
# Tab Action: Context label: 'Execute script...'
# Tab Command:
#* Path: 'gnome-terminal'
#* Parameters: '-x sh -c "%f"'
# Tab Basenames: '*', Must match
# Tab Mimetypes: 'application/x-shellscript', Must match


Tip:
<syntaxhighlight lang=bash>
<blockquote>
gedit ~/.local/share/nautilus/scripts/exec
In Nautilus when opening an executable text file you will have the choice to execute or edit. However, on a NTFS partition each text file is wrongly recognized as executable. You can now disable this choice in Nautilus and still easily execute your scripts with the 'Execute script' action.
</syntaxhighlight>
</blockquote>


<blockquote>
<syntaxhighlight lang=bash>
To disable, in the Nautilus menu go to 'Edit' -> 'Preferences' -> tab 'Behavior', under heading 'Executable Text Files' select 'View as text file when opened'.
#!/bin/bash
</blockquote>
while read -r fn; do
  if [ -n "${fn}" ]; then
    gnome-terminal -e "${fn}"    
  fi
done <<< "${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}"
</syntaxhighlight>


Make the script-file executable:


Export for 'Execute script' action:
<syntaxhighlight lang=bash>
chmod +x ~/.local/share/nautilus/scripts/exec
</syntaxhighlight>


<blockquote>
= See also =  
<syntaxhighlight lang=xml>
* https://fedoramagazine.org/integrating-scripts-nautilus/
<?xml version="1.0" encoding="UTF-8"?>
<gconfentryfile>
  <entrylist base="/apps/nautilus-actions/configurations/343d5295-2162-4850-bd3e-24b683f223d7">
    <entry>
      <key>type</key><value><string>Action</string></value>
    </entry>
    <entry>
      <key>iversion</key><value><int>3</int></value>
    </entry>
    <entry>
      <key>items</key><value><list type="string"><value>
        <string>profile-zero</string></value></list></value>
    </entry>
    <entry>
      <key>label</key><value><string>Execute script...</string></value>
    </entry>
    <entry>
      <key>tooltip</key><value><string>Execute script in terminal</string></value>
    </entry>
    <entry>
      <key>toolbar-label</key><value><string>Execute script...</string></value>
    </entry>
    <entry>
      <key>profile-zero/desc-name</key><value><string>Default profile</string></value>
    </entry>
    <entry>
      <key>profile-zero/path</key><value><string>gnome-terminal</string></value>
    </entry>
    <entry>
      <key>profile-zero/parameters</key><value><string> -x sh -c "%f"</string></value>
    </entry>
    <entry>
      <key>profile-zero/mimetypes</key><value><list type="string"><value>
        <string>application/x-shellscript</string></value></list></value>
    </entry>
  </entrylist>
</gconfentryfile>
</syntaxhighlight>
</blockquote>

Latest revision as of 09:33, 28 September 2018


Add 'Scripts' option to Nautilus. After adding this script you can right-click, go to 'Scripts' and then 'exec'.

You can then disable the Nautilus script-dialog for executable files and pick your text editor as the default application. This dialog is especially annoying for NTFS drives where every text file is considered executable.

Configure

Create the 'Scripts' directory, sub-folders are also possible and will appear as sub-menu-items:

mkdir -p ~/.local/share/nautilus/scripts/

Create the script file, the filename is what will be used in the right-click menu. The script will run in a separate terminal window. It will also work for multiple scripts, one at the time, after each other:

gedit ~/.local/share/nautilus/scripts/exec
	#!/bin/bash
	while read -r fn; do
	  if [ -n "${fn}" ]; then
	    gnome-terminal -e "${fn}"	    
	  fi
	done <<< "${NAUTILUS_SCRIPT_SELECTED_FILE_PATHS}"

Make the script-file executable:

chmod +x ~/.local/share/nautilus/scripts/exec

See also