1 在ubuntu中创建快捷方式
- 在
/ust/local/
下创建文件夹xxx
,并准备下列文件:
xxx/
├── Icon
│ └── 128x128.png
├── xxx.desktop
└── xxx_app
png格式的图标在附件里面找到,.desktop文件编写如下:
[Desktop Entry]
Version=1.0
Type=Application
Name=weizhi
GenericName=Text Editor
Comment=Sophisticated text editor for code, markup and prose
Exec=/usr/local/xxx/xxx_app %F
Terminal=false
MimeType=text/plain;
Icon=/usr/local/xxx/Icon/128x128.png
Categories=TextEditor;Development;
StartupNotify=true
Actions=Window;Document;
[Desktop Action Window]
Name=New Window
Exec=/usr/local/xxx/xxx_app -n
OnlyShowIn=Unity;
[Desktop Action Document]
Name=New File
Exec=/usr/local/xxx/xxx_app --command new_file
OnlyShowIn=Unity;
主要是更改 Exec、Icon 所指向的路径,修改完毕后把此文件复制到/usr/share/applications/
中即可在开始栏中搜索该图标;
2 安装、卸载脚本
为了避免上诉繁琐过程,可以用脚本来自动执行,只需要在程序所在文件夹下添加这三个文件:Icon/128x128.png
、install.sh
、uninstall.sh
,添加完毕后,更改install.sh
和uninstall.sh
文件里的个别名称(有说明),然后在终端执行./install.sh
即可把当前目录下的应用程序拷贝到/usr/local/
下面,并添加快捷方式,文件目录结构如下:
.
├── Icon
│ └── 128x128.png # 快捷方式图片
├── install.sh # 安装脚本
├── my.sh # 可执行应用程序
└── uninstall.sh # 卸载脚本
其中,图片需要自己制作,脚本install.sh
和uninstall.sh
填写的内容如下:
- install.sh
PROGRAM_NAME="app" # 项目名称(自己修改)
APP_NAME="my.sh" # 应用程序的相对路径(自己修改)
ICON_NAME="Icon/128x128.png" # 图标的相对路径(自己修改)
APP_DESKTOP=$PROGRAM_NAME".desktop"
INSTALL_PATH="/usr/local/"$PROGRAM_NAME"/"
if [ ! -f "$APP_NAME" ]; then
echo "Error: can't find "$APP_NAME
echo "Install failed!"
exit
fi
if [ ! -f "$ICON_NAME" ]; then
echo "Error: can't find "$ICON_NAME
echo "Install failed!"
exit
fi
echo "Installed in "$INSTALL_PATH"..."
if [ ! -f "$INSTALL_PATH" ]; then
sudo mkdir $INSTALL_PATH
fi
sudo cp * $INSTALL_PATH -rf
echo "Creat "$APP_DESKTOP"..."
Exec=$INSTALL_PATH$APP_NAME
Icon=$INSTALL_PATH$ICON_NAME
if [ -f "$APP_DESKTOP" ]; then
rm $APP_DESKTOP
fi
echo "[Desktop Entry]" >> $APP_DESKTOP
echo "Version=1.0" >> $APP_DESKTOP
echo "Type=Application" >> $APP_DESKTOP
echo "Name="$PROGRAM_NAME >> $APP_DESKTOP
echo "GenericName=Text Editor" >> $APP_DESKTOP
echo "Comment=Sophisticated text editor for code, markup and prose" >> $APP_DESKTOP
echo "Exec="$Exec" %F" >> $APP_DESKTOP
echo "Terminal=false" >> $APP_DESKTOP
echo "MimeType=text/plain;" >> $APP_DESKTOP
echo "Icon="$Icon >> $APP_DESKTOP
echo "Categories=TextEditor;Development;" >> $APP_DESKTOP
echo "StartupNotify=true" >> $APP_DESKTOP
echo "Actions=Window;Document;" >> $APP_DESKTOP
echo "" >> $APP_DESKTOP
echo "[Desktop Action Window]" >> $APP_DESKTOP
echo "Name=New Window" >> $APP_DESKTOP
echo "Exec="$Exec" -n" >> $APP_DESKTOP
echo "OnlyShowIn=Unity;" >> $APP_DESKTOP
echo "" >> $APP_DESKTOP
echo "[Desktop Action Document]" >> $APP_DESKTOP
echo "Name=New File" >> $APP_DESKTOP
echo "Exec="$Exec" --command new_file" >> $APP_DESKTOP
echo "OnlyShowIn=Unity;" >> $APP_DESKTOP
sudo mv $APP_DESKTOP /usr/share/applications/
echo "Install success!"
- unintall.sh
PROGRAM_NAME="app" # 项目名称(自己修改)
APP_DESKTOP=$PROGRAM_NAME".desktop"
INSTALL_PATH="/usr/local/"$PROGRAM_NAME"/"
sudo rm /usr/share/applications/$APP_DESKTOP
sudo rm $INSTALL_PATH -rf
echo "Uninstall success!"