个人工具

“UbuntuHelp:EjectCDLauncher”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
第2行: 第2行:
 
{{Languages|UbuntuHelp:EjectCDLauncher}}
 
{{Languages|UbuntuHelp:EjectCDLauncher}}
 
You will get an icon on your panel and when you click on it, the cdrom gets unmounted and ejected.
 
You will get an icon on your panel and when you click on it, the cdrom gets unmounted and ejected.
 
 
Create a new file:
 
Create a new file:
 
<pre><nowiki>
 
<pre><nowiki>
 
gksudo gedit /usr/local/bin/eject_cd
 
gksudo gedit /usr/local/bin/eject_cd
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Paste the following lines:
 
Paste the following lines:
 
<pre><nowiki>
 
<pre><nowiki>
 
#! /bin/sh
 
#! /bin/sh
 
 
#
 
#
 
# Try to unmount a CD-Rom device, then eject it.
 
# Try to unmount a CD-Rom device, then eject it.
 
#
 
#
 
 
DEVICE="$1"
 
DEVICE="$1"
 
ZENITY_BIN="/usr/bin/zenity"
 
ZENITY_BIN="/usr/bin/zenity"
 
 
 
#Ctrl-C trapping
 
#Ctrl-C trapping
 
trap ctrlc INT
 
trap ctrlc INT
第28行: 第22行:
 
exit 2
 
exit 2
 
}
 
}
 
 
 
#Show a dialog with zenity
 
#Show a dialog with zenity
 
#@param  string  The text to display
 
#@param  string  The text to display
第38行: 第30行:
 
fi
 
fi
 
}
 
}
 
 
 
#Get parameters
 
#Get parameters
 
if [ "$1" === "-h" ] || [ "$1" === "--help" ] ; then
 
if [ "$1" === "-h" ] || [ "$1" === "--help" ] ; then
第49行: 第39行:
 
exit 0
 
exit 0
 
fi
 
fi
 
 
if [ "$1" === "-z" ] || [ "$1" === "--zenity" ] ; then
 
if [ "$1" === "-z" ] || [ "$1" === "--zenity" ] ; then
 
if [ ! -x "$ZENITY_BIN" ] ; then
 
if [ ! -x "$ZENITY_BIN" ] ; then
第56行: 第45行:
 
fi
 
fi
 
use_zenity="1"
 
use_zenity="1"
 
 
device="$2"
 
device="$2"
 
else
 
else
第62行: 第50行:
 
device="$1"
 
device="$1"
 
fi
 
fi
 
 
 
#Device check
 
#Device check
 
#TODO: Check if DEVICE is truly a device.
 
#TODO: Check if DEVICE is truly a device.
第70行: 第56行:
 
exit 1
 
exit 1
 
fi
 
fi
 
 
 
echo "Trying to eject CD-Rom..."
 
echo "Trying to eject CD-Rom..."
 
 
#Unmount
 
#Unmount
 
umount "$device" 2>/dev/null
 
umount "$device" 2>/dev/null
 
last_err="$?"
 
last_err="$?"
 
 
if [ "$last_err" -eq "1" ] ; then
 
if [ "$last_err" -eq "1" ] ; then
 
msg="Cannot unmount device $device (busy)."
 
msg="Cannot unmount device $device (busy)."
第84行: 第66行:
 
exit 1
 
exit 1
 
fi
 
fi
 
 
#Eject
 
#Eject
 
eject "$device"
 
eject "$device"
 
last_err="$?"
 
last_err="$?"
 
 
if [ "$last_err" -ne "0" ] ; then
 
if [ "$last_err" -ne "0" ] ; then
 
msg="Cannot eject device."
 
msg="Cannot eject device."
第95行: 第75行:
 
exit 1
 
exit 1
 
fi
 
fi
 
 
exit 0
 
exit 0
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Make the script executable:
 
Make the script executable:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo chmod +x /usr/local/bin/eject_cd
 
sudo chmod +x /usr/local/bin/eject_cd
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Create a new launcher on a panel (or wherever you want):
 
Create a new launcher on a panel (or wherever you want):
 
<pre><nowiki>
 
<pre><nowiki>
第110行: 第87行:
 
'Custom Application Launcher'
 
'Custom Application Launcher'
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Type this (replace /dev/cdrom with your CD-Rom device):
 
Type this (replace /dev/cdrom with your CD-Rom device):
 
<pre><nowiki>
 
<pre><nowiki>
第118行: 第94行:
 
Icon: /usr/share/icons/gnome/24x24/devices/gnome-dev-removable.png
 
Icon: /usr/share/icons/gnome/24x24/devices/gnome-dev-removable.png
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Click 'Close'
 
Click 'Close'
 
 
Note:
 
Note:
 
This script uses zenity to display errors. However if you don't want this feature, remove the '-z' parameter.
 
This script uses zenity to display errors. However if you don't want this feature, remove the '-z' parameter.
 
 
To install zenity:
 
To install zenity:
 
<pre><nowiki>
 
<pre><nowiki>
 
sudo apt-get install zenity
 
sudo apt-get install zenity
 
</nowiki></pre>
 
</nowiki></pre>
 
 
Credits: [http://ubuntuforums.org/showthread.php?t=52768 Sam]
 
Credits: [http://ubuntuforums.org/showthread.php?t=52768 Sam]
 
----
 
----

2007年11月30日 (五) 17:03的版本


You will get an icon on your panel and when you click on it, the cdrom gets unmounted and ejected. Create a new file:

gksudo 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

Credits: Sam


A Chinese translation of this article.