特殊:Badtitle/NS100:EjectCDLauncher:修订间差异
小无编辑摘要 |
小无编辑摘要 |
||
第10行: | 第10行: | ||
Paste the following lines: | Paste the following lines: | ||
<pre><nowiki> | <pre><nowiki> | ||
#! /bin/sh | |||
# | |||
# Try to unmount a CD-Rom device, then eject it. | |||
# | |||
DEVICE="$1" | DEVICE="$1" | ||
第16行: | 第20行: | ||
#Ctrl-C trapping | |||
trap ctrlc INT | trap ctrlc INT | ||
ctrlc() | ctrlc() | ||
第25行: | 第30行: | ||
#Show a dialog with zenity | |||
#@param string The text to display | |||
show_dialog() | show_dialog() | ||
{ | { | ||
第33行: | 第40行: | ||
#Get parameters | |||
if [ "$1" === "-h" ] || [ "$1" === "--help" ] ; then | if [ "$1" === "-h" ] || [ "$1" === "--help" ] ; then | ||
echo "Usage: eject_cdrom [-q] DEVICE" | echo "Usage: eject_cdrom [-q] DEVICE" | ||
第56行: | 第64行: | ||
#Device check | |||
#TODO: Check if DEVICE is truly a device. | |||
if [ ! -e "$device" ] ; then | if [ ! -e "$device" ] ; then | ||
echo "Parameter DEVICE is not a file." | echo "Parameter DEVICE is not a file." | ||
第64行: | 第74行: | ||
echo "Trying to eject CD-Rom..." | echo "Trying to eject CD-Rom..." | ||
#Unmount | |||
umount "$device" 2>/dev/null | umount "$device" 2>/dev/null | ||
last_err="$?" | last_err="$?" | ||
第74行: | 第85行: | ||
fi | fi | ||
#Eject | |||
eject "$device" | eject "$device" | ||
last_err="$?" | last_err="$?" |
2007年5月24日 (四) 09:35的版本
文章出处: |
{{#if: | {{{2}}} | https://help.ubuntu.com/community/EjectCDLauncher }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/af | • {{#if: UbuntuHelp:EjectCDLauncher|Afrikaans| [[::EjectCDLauncher/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ar | • {{#if: UbuntuHelp:EjectCDLauncher|العربية| [[::EjectCDLauncher/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/az | • {{#if: UbuntuHelp:EjectCDLauncher|azərbaycanca| [[::EjectCDLauncher/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/bcc | • {{#if: UbuntuHelp:EjectCDLauncher|جهلسری بلوچی| [[::EjectCDLauncher/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/bg | • {{#if: UbuntuHelp:EjectCDLauncher|български| [[::EjectCDLauncher/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/br | • {{#if: UbuntuHelp:EjectCDLauncher|brezhoneg| [[::EjectCDLauncher/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ca | • {{#if: UbuntuHelp:EjectCDLauncher|català| [[::EjectCDLauncher/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/cs | • {{#if: UbuntuHelp:EjectCDLauncher|čeština| [[::EjectCDLauncher/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/de | • {{#if: UbuntuHelp:EjectCDLauncher|Deutsch| [[::EjectCDLauncher/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/el | • {{#if: UbuntuHelp:EjectCDLauncher|Ελληνικά| [[::EjectCDLauncher/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/es | • {{#if: UbuntuHelp:EjectCDLauncher|español| [[::EjectCDLauncher/es|español]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/fa | • {{#if: UbuntuHelp:EjectCDLauncher|فارسی| [[::EjectCDLauncher/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/fi | • {{#if: UbuntuHelp:EjectCDLauncher|suomi| [[::EjectCDLauncher/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/fr | • {{#if: UbuntuHelp:EjectCDLauncher|français| [[::EjectCDLauncher/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/gu | • {{#if: UbuntuHelp:EjectCDLauncher|ગુજરાતી| [[::EjectCDLauncher/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/he | • {{#if: UbuntuHelp:EjectCDLauncher|עברית| [[::EjectCDLauncher/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/hu | • {{#if: UbuntuHelp:EjectCDLauncher|magyar| [[::EjectCDLauncher/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/id | • {{#if: UbuntuHelp:EjectCDLauncher|Bahasa Indonesia| [[::EjectCDLauncher/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/it | • {{#if: UbuntuHelp:EjectCDLauncher|italiano| [[::EjectCDLauncher/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ja | • {{#if: UbuntuHelp:EjectCDLauncher|日本語| [[::EjectCDLauncher/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ko | • {{#if: UbuntuHelp:EjectCDLauncher|한국어| [[::EjectCDLauncher/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ksh | • {{#if: UbuntuHelp:EjectCDLauncher|Ripoarisch| [[::EjectCDLauncher/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/mr | • {{#if: UbuntuHelp:EjectCDLauncher|मराठी| [[::EjectCDLauncher/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ms | • {{#if: UbuntuHelp:EjectCDLauncher|Bahasa Melayu| [[::EjectCDLauncher/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/nl | • {{#if: UbuntuHelp:EjectCDLauncher|Nederlands| [[::EjectCDLauncher/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/no | • {{#if: UbuntuHelp:EjectCDLauncher|norsk| [[::EjectCDLauncher/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/oc | • {{#if: UbuntuHelp:EjectCDLauncher|occitan| [[::EjectCDLauncher/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/pl | • {{#if: UbuntuHelp:EjectCDLauncher|polski| [[::EjectCDLauncher/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/pt | • {{#if: UbuntuHelp:EjectCDLauncher|português| [[::EjectCDLauncher/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ro | • {{#if: UbuntuHelp:EjectCDLauncher|română| [[::EjectCDLauncher/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/ru | • {{#if: UbuntuHelp:EjectCDLauncher|русский| [[::EjectCDLauncher/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/si | • {{#if: UbuntuHelp:EjectCDLauncher|සිංහල| [[::EjectCDLauncher/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/sq | • {{#if: UbuntuHelp:EjectCDLauncher|shqip| [[::EjectCDLauncher/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/sr | • {{#if: UbuntuHelp:EjectCDLauncher|српски / srpski| [[::EjectCDLauncher/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/sv | • {{#if: UbuntuHelp:EjectCDLauncher|svenska| [[::EjectCDLauncher/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/th | • {{#if: UbuntuHelp:EjectCDLauncher|ไทย| [[::EjectCDLauncher/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/tr | • {{#if: UbuntuHelp:EjectCDLauncher|Türkçe| [[::EjectCDLauncher/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/vi | • {{#if: UbuntuHelp:EjectCDLauncher|Tiếng Việt| [[::EjectCDLauncher/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/yue | • {{#if: UbuntuHelp:EjectCDLauncher|粵語| [[::EjectCDLauncher/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/zh | • {{#if: UbuntuHelp:EjectCDLauncher|中文| [[::EjectCDLauncher/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/zh-hans | • {{#if: UbuntuHelp:EjectCDLauncher|中文(简体)| [[::EjectCDLauncher/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuHelp:EjectCDLauncher | UbuntuHelp:EjectCDLauncher | {{#if: | :}}EjectCDLauncher}}/zh-hant | • {{#if: UbuntuHelp:EjectCDLauncher|中文(繁體)| [[::EjectCDLauncher/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuHelp:EjectCDLauncher|:EjectCDLauncher|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :EjectCDLauncher/zh | | {{#ifexist: EjectCDLauncher/zh | | {{#ifeq: {{#titleparts:EjectCDLauncher|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:EjectCDLauncher|1|-1|}} | zh | | }}
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.