Kr@z7_&_U3vNtv_$>

[Fixed] Phím tắt cho GNOME trên Jaunty Jacklope

Posted in GNOME Desktop, Ubuntu by krazv7rvn9 on 03/06/2009

Sau một hồi google lung tung, tôi đã tìm ra cách đặt phím tắt trên Jaunty Jacklope. Lời giải ở đây!

Trên các bản Ubuntu trước (từ Intrepid trở xuống), để thiết lập phím tắt cho GNOME, ta có 2 cách:

1 – Nhấn Alt+F2, gõ gconf-editor và Enter. Trong cây khóa ở bên trái, duyệt tới /apps/metacity/global_keybindings. Ở ô bên phải, ta sẽ thấy có các khóa run_command_x (x từ 1 – 12). Sửa nội dung các khóa này thành phím tắt muốn dùng. Sau đó chọn tiếp khóa /apps/metacity/keybinding_commands ở ô bên trái. Trong ô bên phải lúc này sẽ có các khóa tên là command_x (x từ 1 – 12). Nhập lệnh cần chạy tương ứng với phím tắt đã nhập vào ô run_command_x ở trên. Ví dụ:

  • run_command_1: <Control><Alt>f
  • command_1: firefox

2 – Cài thêm gói compizconfig-settings-manager rồi sử dụng plugin Commands của nó để quy định các phím tắt, tương tự như trên.

Cách 1 trên Jaunty không hoạt động nữa. Cách 2 thì vẫn chạy được, nhưng phải cài thêm trình quản lý compiz. Với tôi, chừng này hiệu ứng là đủ, và tôi thích dùng metacity hơn là emerald.

Sự thực thì ở bản này, vị trí các khóa trong gconf-editor đã thay đổi. Thay vì /apps/metacity/, để cấu hình phím tắt, ta phải sửa khóa /desktop/gnome/keybindings.

Xem trong hướng dẫn từ ubuntu-forum, tôi viết 1 bash script để làm việc này:

#!/bin/bash
# Custom shortcut keys for GNOME
# Ubuntu 9.04 Jaunty Jacklope

# Gedit shortcut
echo -n “Configuring shortcut key for gedit…”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom1/binding “<Control><Alt>g”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom1/name “GEdit”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom1/action “gedit –new-document”
echo “Done.”

# Bluefish Editor
echo -n “Configuring shortcut key for Bluefish Editor…”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom2/binding “<Control><Alt>b”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom2/name “Bluefish”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom2/action “bluefish-unstable”
echo “Done.”

# Exaile
echo -n “Configuring shortcut key for Exail Music Player…”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom3/binding “<Control><Alt>m”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom3/name “Exaile Music Player”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom3/action “exaile”
echo “Done.”

# Firefox
echo -n “Configuring shortcut key for Firefox…”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom4/binding “<Control><Alt>f”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom4/name “Firefox”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom4/action “firefox”
echo “Done.”

# Evolution
echo -n “Configuring shortcut key for Evolution…”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom5/binding “<Control><Alt>e”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom5/name “Evolution”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom5/action “evolution”
echo “Done.”

# Pidgin
echo -n “Configuring shortcut key for Pidgin…”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom6/binding “<Control><Alt>p”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom6/name “Pidgin”
gconftool-2 -t str  –set /desktop/gnome/keybindings/custom6/action “pidgin”
echo “Done.”

Câu lệnh gconftool-2 có vai trò tương tự như gconf-editor, cho phép sửa dữ liệu registry của GNOME. Đơn giản là ta sẽ thêm vào 1 thư mục khóa customx (x là 1 số tự chọn), với 3 khóa có nội dung là:

  • binding : tổ hợp phím bạn muốn dùng. <Control> cho phím Ctrl, <Alt> cho phím Alt, <Shift> cho phím Shift.
  • name : Đặt tên ứng dụng muốn chạy.
  • action: Câu lệnh để khởi chạy ứng dụng.

Ta có thể thêm bao nhiêu phím tắt vào cho GNOME cũng được. Chỉ việc chép lại 3 dòng lệnh trên (2 dòng echo cho nó đẹp), và sửa lại đánh số x cho thư mục khóa, cùng với tên và câu lệnh là được.

Sau đó ta chạy file này (với tài khoản của mình, không cần dùng sudo hay chuyển sang tài khoản root đâu!)

dinhtrung@dinhtrung-laptop:~$ bash /home/dinhtrung/Documents/Bash\ scripts/Jaunty-shortcuts.txt

Thật là tiện dụng phải không? Tí nữa là đánh giá thấp Jaunty rồi!

Follow

Get every new post delivered to your Inbox.