个人工具

UbuntuHelp:EjectCDLauncher/zh

来自Ubuntu中文

跳转至: 导航, 搜索


本文介绍如何在面板上添加一个图标,通过点击它即可卸载和弹出CDROM.

步骤:

创建一个新文件

gksudo gedit /usr/local/bin/eject_cd

粘贴如下代码

<nowike>
DEVICE="$1"
ZENITY_BIN="/usr/bin/zenity"


trap ctrlc INT
ctrlc()
{
echo -e "\nAborted by user."
rm -rf $TMP_DIR
exit 2
}


show_dialog()
{
if [ "$use_zenity" -gt "0" ] ; then
zenity --error --title "CD-Rom eject" --info-text "$1"
fi
}


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


if [ ! -e "$device" ] ; then
echo "Parameter DEVICE is not a file."
exit 1
fi


echo "Trying to eject CD-Rom..."

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 "$device"
last_err="$?"

if [ "$last_err" -ne "0" ] ; then
msg="Cannot eject device."
echo "$msg"
show_dialog "$msg"
exit 1
fi

exit 0
</nowiki>

给该文件加上可执行属性:

sudo chmod +x /usr/local/bin/eject_cd

在桌面面板创建一个启动器(或其他你喜欢地方)

Right-click on the panel
'Add to Panel'
'Custom Application Launcher'
在右键点击桌面面板
‘添加到面板’
‘用户自定义应用程序’

输入信息(根据你实际的CDROM设备路径,替换 /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
名字: 弹出CDROM
备注:卸载,弹出CDROM
命令:/usr/local/bin/eject_cd -z /dev/cdrom
图标:/usr/share/icons/gnome/24x24/devices/gnome-dev-removable.png

点击‘关闭’

注:这个脚本调用了zentity来提示错误,如果你不想要这个功能,那么删除 ‘-z’这个参数。

安装zenity:

sudo apt-get install zenity