EjectCDLauncher
原文出处:https://help.ubuntu.com/community/EjectCDLauncher
原文作者:UbuntuWiki
授权许可:
翻译人员:leal
校对人员:MillenniumDark
贡献者:
适用版本: 文章状态:完成
You will get an icon on your panel and when you click on it, the cdrom gets unmounted and ejected.
Create a new file:
你的面板上会增加一个图标,当你点击它时,cdrom就会卸载并弹出。
创建一个新文件:
sudo gedit /usr/local/bin/eject_cd
Paste the following lines:
把下列内容粘贴到文件中:
#! /bin/sh # # Try to unmount a CD-Rom device, then eject it. # DEVICE="$1" ZENITY_BIN="/usr/bin/zenity" #Ctrl-C trapping trap ctrlc INT ctrlc() { echo -e "\nAborted by user." rm -rf $TMP_DIR exit 2 } #Show a dialog with zenity #@param string The text to display show_dialog() { if [ "$use_zenity" -gt "0" ] ; then zenity --error --title "CD-Rom eject" --info-text "$1" fi } #Get parameters if [ "$1" === "-h" ] || [ "$1" === "--help" ] ; then echo "Usage: eject_cdrom [-q] DEVICE" echo -e "Try to unmount DEVICE then eject it if successful.\n" echo "Possible parameters:" echo -e "-h, --help\tdisplay this help and exit." echo -e "-z, --zenity\tuse zenity to displays errors in dialog windows." exit 0 fi if [ "$1" === "-z" ] || [ "$1" === "--zenity" ] ; then if [ ! -x "$ZENITY_BIN" ] ; then echo "You must install zenity before that." exit 1 fi use_zenity="1" device="$2" else use_zenity="0" device="$1" fi #Device check #TODO: Check if DEVICE is truly a device. if [ ! -e "$device" ] ; then echo "Parameter DEVICE is not a file." exit 1 fi echo "Trying to eject CD-Rom..." #Unmount umount "$device" 2>/dev/null last_err="$?" if [ "$last_err" -eq "1" ] ; then msg="Cannot unmount device $device (busy)." echo "$msg" show_dialog "$msg" exit 1 fi #Eject eject "$device" last_err="$?" if [ "$last_err" -ne "0" ] ; then msg="Cannot eject device." echo "$msg" show_dialog "$msg" exit 1 fi exit 0
Make the script executable:
把该脚本设为可执行:
sudo chmod +x /usr/local/bin/eject_cd
Create a new launcher on a panel (or wherever you want):
在面板上(或其它你喜欢的地方)创建一个新的启动器:
Right-click on the panel 'Add to Panel' 'Custom Application Launcher'
Type this (replace /dev/cdrom with your CD-Rom device):
输入下列内容(用你的CD-Rom设备替代/dev/cdrom):
Name: Eject CD-Rom Comment: Unmount and eject the CD-Rom /dev/cdrom Command: /usr/local/bin/eject_cd -z /dev/cdrom Icon: /usr/share/icons/gnome/24x24/devices/gnome-dev-removable.png
Click 'Close'
单击'Close'(关闭)
Note: This script uses zenity to display errors. However if you don't want this feature, remove the '-z' parameter.
To install zenity:
注:这个脚本使用zenity来显示错误信息。当然如果你不需要该特性,只需移除'-z'参数。
如下命令可安装zenity:
sudo apt-get install zenity
Credits: Sam