You will get an icon on your panel and when you click on it, the cdrom gets unmounted and ejected.
Create a new file:
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):
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'
Note: This script uses zenity to display errors. However if you don't want this feature, remove the '-z' parameter.
To install zenity:
sudo apt-get install zenity
https://wiki.ubuntu.com/EjectCDLauncher
[wiki]EjectCDLauncher
- oneleaf
- 论坛管理员
- 帖子: 10454
- 注册时间: 2005-03-27 0:06
- 系统: Ubuntu 12.04
- leal
- 帖子: 1119
- 注册时间: 2005-08-29 14:49
- 来自: 杭州
- 联系:
Re: EjectCDLauncher
你的面板上会增加一个图标,当你点击它时,cdrom就会卸载并弹出。
创建一个新文件:
sudo gedit /usr/local/bin/eject_cd
把下列内容粘贴到文件中:
#! /bin/sh
#
# Try to unmount a CD-Rom device, then eject it.
# (旨在卸载CD-Rom设备,然后弹出。)
DEVICE="$1"
ZENITY_BIN="/usr/bin/zenity"
#Ctrl-C trapping(捕获Ctrl-C)
trap ctrlc INT
ctrlc()
{
echo -e "\nAborted by user."
rm -rf $TMP_DIR
exit 2
}
#Show a dialog with zenity(显示含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.(检查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
把该脚本设为可执行:
sudo chmod +x /usr/local/bin/eject_cd
在面板上(或其它你喜欢的地方)创建一个新的启动器:
在面板上右键单击:
'Add to Panel'(添加到面板上)
'Custom Application Launcher'(定制程序启动器)
输入下列内容(用你的CD-Rom设备替代/dev/cdrom):
名称:Eject CD-Rom(弹出CD-Rom)
注释:Unmount and eject the CD-Rom /dev/cdrom(卸载并弹出CD-Rom /dev/cdrom)
命令: /usr/local/bin/eject_cd -z /dev/cdrom
图标:/usr/share/icons/gnome/24x24/devices/gnome-dev-removable.png
单击'Close'(关闭)
注:这个脚本使用zenity来显示错误信息。当然如果你不需要该特性,只需移除'-z'参数。
如下命令可安装zenity:
sudo apt-get install zenity
https://wiki.ubuntu.com/EjectCDLauncher
创建一个新文件:
sudo gedit /usr/local/bin/eject_cd
把下列内容粘贴到文件中:
#! /bin/sh
#
# Try to unmount a CD-Rom device, then eject it.
# (旨在卸载CD-Rom设备,然后弹出。)
DEVICE="$1"
ZENITY_BIN="/usr/bin/zenity"
#Ctrl-C trapping(捕获Ctrl-C)
trap ctrlc INT
ctrlc()
{
echo -e "\nAborted by user."
rm -rf $TMP_DIR
exit 2
}
#Show a dialog with zenity(显示含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.(检查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
把该脚本设为可执行:
sudo chmod +x /usr/local/bin/eject_cd
在面板上(或其它你喜欢的地方)创建一个新的启动器:
在面板上右键单击:
'Add to Panel'(添加到面板上)
'Custom Application Launcher'(定制程序启动器)
输入下列内容(用你的CD-Rom设备替代/dev/cdrom):
名称:Eject CD-Rom(弹出CD-Rom)
注释:Unmount and eject the CD-Rom /dev/cdrom(卸载并弹出CD-Rom /dev/cdrom)
命令: /usr/local/bin/eject_cd -z /dev/cdrom
图标:/usr/share/icons/gnome/24x24/devices/gnome-dev-removable.png
单击'Close'(关闭)
注:这个脚本使用zenity来显示错误信息。当然如果你不需要该特性,只需移除'-z'参数。
如下命令可安装zenity:
sudo apt-get install zenity
https://wiki.ubuntu.com/EjectCDLauncher
- oneleaf
- 论坛管理员
- 帖子: 10454
- 注册时间: 2005-03-27 0:06
- 系统: Ubuntu 12.04
- millenniumdark
- 论坛版主
- 帖子: 4159
- 注册时间: 2005-07-02 14:41
- 系统: Ubuntu 14.04 (Kylin)
- 联系: