当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 4 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [wiki]EjectCDLauncher
帖子发表于 : 2005-10-01 12:10 
论坛管理员

注册: 2005-03-27 0:06
帖子: 10110
系统: Ubuntu 12.04
送出感谢: 7
接收感谢: 127
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


页首
 用户资料  
 
2 楼 
 文章标题 : Re: EjectCDLauncher
帖子发表于 : 2005-10-01 23:39 
头像

注册: 2005-08-29 14:49
帖子: 1119
地址: 杭州
送出感谢: 0 次
接收感谢: 3
你的面板上会增加一个图标,当你点击它时,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


_________________
用心×恒 | 豆瓣 | 门户 | Blog


页首
 用户资料  
 
3 楼 
 文章标题 :
帖子发表于 : 2005-10-11 12:55 
论坛管理员

注册: 2005-03-27 0:06
帖子: 10110
系统: Ubuntu 12.04
送出感谢: 7
接收感谢: 127
http://www.ubuntu.org.cn/support/docume ... howto_view


页首
 用户资料  
 
4 楼 
 文章标题 :
帖子发表于 : 2006-07-30 1:30 
头像

注册: 2005-07-02 14:41
帖子: 4133
系统: Ubuntu 14.04 (Kylin)
送出感谢: 53
接收感谢: 11
http://wiki.ubuntu.org.cn/EjectCDLauncher


_________________
https://weakish.github.io


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 4 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译