Mate 黃金右鍵初步研究測試 [論壇 - LinuxMint]
正在瀏覽:
1 名遊客
Mate 黃金右鍵初步研究測試 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2015/9/29 21:19 所屬群組:
已註冊使用者 等級: 16
HP : 0 / 380
![]() |
這東西要做個乾淨而且全域性的腳本實在很難
同樣自gnome2分家出來的cinnamon體質就很好 cinnamon本身就是Linux Mint官方開發出來的 Linux Mint 也是愛集成黃金右鍵的,所以先天體質固然很好. 當然也有一些工具可以完成黃金右鍵, 比如 Caja-Actions... 不過都不是全域性乾淨完美的作法, 語法也不喜歡. 寫在USER目錄那種白ㄘ方法, 當系統重灌就得重新設定. 不過試了 caja-pyextensions 研究後發現. 也是可以實現乾淨而且全域性的作法 只是要用python腳本而已. 作法也很簡單, 不用安裝 caja-pyextensions sudo apt-get install python-caja 然後把寫好的腳本放入 /usr/share/caja-python/extensions 重登或重新啟動後,黃金右鍵就出來了 ![]() 改自caja-pyextensions的兩個基本腳本 以Root權限開啟 /usr/share/caja-python/extensions/open-as-root.py
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""This module adds a menu item to the Caja right-click menu which allows to
open the selected file/folder as root user, so having administrator rights"""
from gi.repository import Caja, GObject, Gtk, GdkPixbuf
import urllib, subprocess, re
import gettext, locale
ICONPATH = "/usr/share/pixmaps/gksu.png"
LOCALE_PATH = "/usr/share/locale/"
locale.setlocale(locale.LC_ALL, '')
_ = gettext.gettext
class OpenAsRoot(GObject.GObject, Caja.MenuProvider):
"""Implements the 'Open as Root' extension to the Caja right-click menu"""
def __init__(self):
"""Caja crashes if a plugin doesn't implement the __init__ method"""
try:
factory = Gtk.IconFactory()
pixbuf = GdkPixbuf.Pixbuf.new_from_file(ICONPATH)
iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
factory.add("gksu", iconset)
factory.add_default()
except: pass
def run(self, menu, source_path):
"""Runs the Opening of the selected File/Folder as Root User"""
subprocess.call("sudo caja %s &" % source_path, shell=True)
def get_file_items(self, window, sel_items):
"""Adds the 'Open as Root' menu item to the Caja right-click menu,
connects its 'activate' signal to the 'run' method passing the selected File/Folder"""
if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return
uri_raw = sel_items[0].get_uri()
if len(uri_raw) < 7: return
source_path = urllib.unquote(uri_raw[7:])
item = Caja.MenuItem(name='CajaPython::gksu',
label=_('Open as Root'),
tip=_('Open the selected File/Folder as Root User'),
icon='gksu')
item.connect('activate', self.run, re.escape(source_path))
return [item]
在此開啟終端機 /usr/share/caja-python/extensions/open-terminal-here.py
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""This module adds a menu item to the Caja right-click menu which allows to Open the Terminal
on the Selected Folder/Current Directory at predefined Geometry just through the right-clicking"""
from gi.repository import Caja, GObject, Gtk, GdkPixbuf
import urllib, os, subprocess
import gettext, locale
ICONPATH = "/usr/share/icons/gnome/48x48/apps/terminal.png"
LOCALE_PATH = "/usr/share/locale/"
locale.setlocale(locale.LC_ALL, '')
_ = gettext.gettext
class OpenTerminalHere(GObject.GObject, Caja.MenuProvider):
"""Implements the 'Open Terminal Here' extension to the caja right-click menu"""
def __init__(self):
"""Caja crashes if a plugin doesn't implement the __init__ method"""
try:
factory = Gtk.IconFactory()
pixbuf = GdkPixbuf.Pixbuf.new_from_file(ICONPATH)
iconset = Gtk.IconSet.new_from_pixbuf(pixbuf)
factory.add("terminal", iconset)
factory.add_default()
except: pass
def run(self, menu, selected):
"""Runs the Open Terminal Here on the given Directory"""
uri_raw = selected.get_uri()
if len(uri_raw) < 7: return
curr_dir = urllib.unquote(uri_raw[7:])
if os.path.isfile(curr_dir): curr_dir = os.path.dirname(curr_dir)
bash_string = "cd \"" + curr_dir + "\" && mate-terminal &"
subprocess.call(bash_string, shell=True)
def get_file_items(self, window, sel_items):
"""Adds the 'Open Terminal Here' menu item to the Caja right-click menu,
connects its 'activate' signal to the 'run' method passing the selected Directory/File"""
if len(sel_items) != 1 or sel_items[0].get_uri_scheme() != 'file': return
item = Caja.MenuItem(name='CajaPython::terminal',
label=_('Open Terminal Here'),
tip=_('Open the Terminal on the Current/Selected Directory'),
icon='terminal')
item.connect('activate', self.run, sel_items[0])
return [item]
def get_background_items(self, window, current_directory):
"""Adds the 'Open Terminal Here' menu item to the Caja right-click menu,
connects its 'activate' signal to the 'run' method passing the current Directory"""
item = Caja.MenuItem(name='CajaPython::terminal',
label=_('Open Terminal Here'),
tip=_('Open the Terminal on the Current Directory'),
icon='terminal')
item.connect('activate', self.run, current_directory)
return [item]
2016/3/19 1:22
|
||||||||||
![]() |
回覆: Mate 黃金右鍵初步研究測試 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2015/9/29 21:19 所屬群組:
已註冊使用者 等級: 16
HP : 0 / 380
![]() |
python腳本對不會python的一般使用者有高難度, 自訂性不高.
最佳的工具仍然是 Caja-Actions 之前把設定檔搞混, 誤以為HOME/.config/caja-actions/caja-actions.conf 是全部動作設定參數. 仍然不死心,下載原始碼來看一下. caja-actions設定檔 檔案: caja-actions-1.8.0/src/core/na-settings.h * - global configuration is sysconfdir/xdg/caja-actions/caja-actions.conf * - per-user configuration is HOME/.config/caja-actions/caja-actions.conf 全域性設定檔為: /etc/xdg/caja-actions/caja-actions.conf caja-actions動作參數 檔案: caja-actions-1.8.0/src/io-desktop/cadp-formats.c XDG_DATA_DIRS/file-manager/actions directory 測試一下路徑 $ cd $XDG_DATA_DIRS bash: cd: /usr/share/mate:/usr/share/mate:/usr/local/share/:/usr/share/:/usr/share/mdm/: 沒有此一檔案或目錄 表示"file-manager/actions"放在以上幾個目錄都可以 全域性動作參數目錄為 /usr/local/share/file-manager/actions/ 或 /usr/share/file-manager/actions/ 例如選擇/usr/share/file-manager/actions/當動作參數腳本目錄 $ sudo mkdir /usr/share/file-manager $ sudo mkdir /usr/share/file-manager/actions 安裝 caja-actions $ sudo apt-get install caja-actions 實現第一個腳本 $ sudo leafpad /usr/share/file-manager/actions/open-as-root.desktop [Desktop Entry]
Type=Action
Icon=folder_open
Name=open as root
Name[zh_TW]=以管理員權限開啟
Profiles=profile-zero;
TargetLocation=true
[X-Action-Profile profile-zero]
Exec=sudo caja %f 如果不喜歡右鍵蝸牛殼子選單模式 去蝸牛殼子選單模式 $ mkdir /etc/xdg/caja-actions $ sudo leafpad /etc/xdg/caja-actions/caja-actions.conf [runtime]
items-create-root-menu=false 清除 Home 目錄設定檔 $ rm -rf ~/.config/caja-actions $ rm -rf ~/.local/share/file-manager 重登或重新啟動永久生效 ![]()
2016/3/19 13:13
|
||||||||||
![]() |
回覆: Mate 黃金右鍵初步研究測試 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2015/9/29 21:19 所屬群組:
已註冊使用者 等級: 16
HP : 0 / 380
![]() |
深入了解後發現, 這確實是好物. python腳本可以丟了
![]() 腳本接二連三實現.. 先補齊Mint的基本黃金右鍵 在此開啟終端機 $ sudo leafpad /usr/share/file-manager/actions/open-terminal-here.desktop [Desktop Entry] Type=Action Icon=utilities-terminal Name=Open a terminal here Name[zh_TW]=在此開啟終端機 Profiles=profile-zero; TargetLocation=true [X-Action-Profile profile-zero] Exec=mate-terminal MimeTypes=inode/directory; Path=%f Mint-檢查MD5 (mint專屬) $ sudo leafpad /usr/share/file-manager/actions/mint-md5sum.desktop [Desktop Entry] Type=Action Icon=gnome-run Name=Check MD5 Name[zh_TW]=檢查MD5 Profiles=profile-zero; [X-Action-Profile profile-zero] Basenames=*.iso;*.ISO;*.nrg;*.NRG; Exec=mint-md5sum %f mint-檔案搜尋(要安裝 catfish 重點在於可搜尋檔案內容文字) ![]() $ sudo leafpad /usr/share/file-manager/actions/catfish.desktop [Desktop Entry] Type=Action Icon=gtk-find Name=Search for Files Name[zh_TW]=檔案搜尋 Profiles=profile-zero; TargetLocation=true [X-Action-Profile profile-zero] MimeTypes=inode/directory; Exec=catfish %f mint-建立連結(如果沒出現連結, 重新載入後連結才會跑出來) $ sudo leafpad /usr/share/file-manager/actions/create-link.desktop [Desktop Entry] Type=Action Icon=emblem-symbolic-link Name=Create a Link Name[zh_TW]=建立連結 Profiles=profile-zero; [X-Action-Profile profile-zero] Exec=ln -s %f 'Link to %b'
2016/3/19 19:05
|
||||||||||
![]() |
回覆: Mate 黃金右鍵初步研究測試 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2015/9/29 21:19 所屬群組:
已註冊使用者 等級: 16
HP : 0 / 380
![]() |
掛載映像檔 (iso nrg squashfs壓縮格式)
$ sudo leafpad /usr/share/file-manager/actions/mount-image.desktop [Desktop Entry] Type=Action Icon=media-optical Name=Mount Image Name[zh_TW]=掛載映像檔 Profiles=profile-zero; [X-Action-Profile profile-zero] Basenames=*.iso;*.ISO;*.nrg;*.NRG;*.squashfs;*.sqfs;*.sfs; Exec=mount-image %f %b $ sudo leafpad /usr/bin/mount-image #!/bin/bash file=$1 name=$2 case "${1##*.}" in "iso"|"ISO") sudo mkdir /run/media sudo mkdir /run/media/$USER sudo mkdir /run/media/$USER/$name sudo mount -o loop $file /run/media/$USER/$name ;; "nrg"|"NRG") sudo mkdir /run/media sudo mkdir /run/media/$USER sudo mkdir /run/media/$USER/$name sudo mount -o loop,offset=307200 $file /run/media/$USER/$name ;; "squashfs"|"sfs"|"sqfs") sudo mkdir /run/media sudo mkdir /run/media/$USER sudo mkdir /run/media/$USER/$name sudo mount -t squashfs $file /run/media/$USER/$name ;; esac 賦予權限 $ sudo chmod 755 /usr/bin/mount-image
2016/3/19 19:42
|
||||||||||
![]() |
回覆: Mate 黃金右鍵初步研究測試 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2015/9/29 21:19 所屬群組:
已註冊使用者 等級: 16
HP : 0 / 380
![]() |
DEB解壓縮/打包(修改現有DEB套件專用)
$ sudo leafpad /usr/share/file-manager/actions/deb-unpack.desktop [Desktop Entry] Type=Action Icon=gnome-mime-application-x-deb Name=Unpack DEB Name[zh_TW]=解壓縮DEB Profiles=profile-zero; [X-Action-Profile profile-zero] MimeTypes=application/vnd.debian.binary-package; Exec=sudo deb-unpack %b $ sudo leafpad /usr/share/file-manager/actions/deb-pack.desktop [Desktop Entry] Type=Action Icon=softwarecenter-debian Name=Rebuild DEB Name[zh_TW]=重建DEB Profiles=profile-zero; [X-Action-Profile profile-zero] MimeTypes=inode/directory; Basenames=*.deb.upk; Exec=sudo deb-pack %b $ sudo leafpad /usr/bin/deb-unpack #!/bin/bash name=$1 dpkg -X $name deb cd deb dpkg -e ../$name cd ../ rm $name rm deb/DEBIAN/md5sums mv deb $name".upk" zenity --title="DEB Utility" --info --text="Extract DEB binary-package Successfully." $ sudo leafpad /usr/bin/deb-pack #!/bin/bash name=$1 debname="${name%.*}" md5dir="bin lib lin64 opt sbin usr" cd $name find $md5dir -type f -exec md5sum {} > DEBIAN/md5sums \; cd ../ sudo dpkg -b $name $debname zenity --title="DEB Utility" --info --text="Rebuild DEB binary-package Successfully." 賦予權限 $ sudo chmod 755 /usr/bin/deb-pack $ sudo chmod 755 /usr/bin/deb-unpack
2016/3/19 19:49
|
||||||||||
![]() |
回覆: Mate 黃金右鍵初步研究測試 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2015/9/29 21:19 所屬群組:
已註冊使用者 等級: 16
HP : 0 / 380
![]() |
initramfs 解壓縮與重建 (debian/ubuntu/archlinux/manjaro)
$ sudo leafpad /usr/share/file-manager/actions/initrd-unpack.desktop [Desktop Entry] Type=Action Icon=gnome-package Name=Unpack initrd Name[zh_TW]=解壓縮 initrd Profiles=profile-zero; [X-Action-Profile profile-zero] Basenames=initrd.img;initrd.gz;initrd.lz;initramfs-linux.img;manjaro.img;archiso.img; Exec=initrd-unpack %f %b $ sudo leafpad /usr/share/file-manager/actions/initrd-pack.desktop [Desktop Entry] Type=Action Icon=gnome-package Name=Rebuild initrd Name[zh_TW]=重建 initrd Profiles=profile-zero; [X-Action-Profile profile-zero] MimeTypes=inode/directory; Basenames=rootfs; Exec=initrd-pack %b $ sudo leafpad /usr/bin/initrd-unpack #!/bin/bash file=$1 name=$2 ftype=$(file -b $file) case $ftype in "XZ"*) mv $name initrd.xz xz -d initrd.xz mkdir rootfs ;; "LZMA"*) mv $name initrd.lzma lzma -d initrd.lzma mkdir rootfs ;; "gzip"*) mv $name initrd.gz gzip -d initrd.gz mkdir rootfs ;; esac cd rootfs cpio -i -F ../initrd rm ../initrd zenity --title="initramfs utility" --info --text="extract initramfs successfully." $ sudo leafpad /usr/bin/initrd-pack #!/bin/bash name=$1 cd $name find . | cpio -o --format=newc > ../initrd cd ../ gzip -c initrd > initrd.gz rm -rf initrd rm -rf rootfs zenity --title="initramfs utility" --info --text="rebuild initramfs successfully." 賦予權限 $ sudo chmod 755 /usr/bin/initrd-unpack $ sudo chmod 755 /usr/bin/initrd-pack
2016/3/19 19:54
|
||||||||||
![]() |
您可以查看帖子.
您不可發帖.
您不可回覆.
您不可編輯自己的帖子.
您不可刪除自己的帖子.
您不可發起投票調查.
您不可在投票調查中投票.
您不可上傳附件.
您不可不經審核直接發帖.