请人制作一个网站需要多少钱,沈阳建设工程招投标网,男女的做那个视频网站,网站建设 流程 域名申请Ubuntu 创建应用图标的方式汇总#xff0c;deb/appimage/通用方法
对于标准的 Ubuntu#xff08;使用 GNOME 桌面#xff09;#xff0c;desktop 后缀的桌面图标文件主要保存在以下三个路径#xff1a;
当前用户的桌面目录#xff08;这是最常见的位置#xff09;。所…Ubuntu 创建应用图标的方式汇总deb/appimage/通用方法
对于标准的 Ubuntu使用 GNOME 桌面desktop 后缀的桌面图标文件主要保存在以下三个路径
当前用户的桌面目录这是最常见的位置。所有放在这个目录中的.desktop文件、文件夹或快捷方式会显示在桌面上如果桌面图标功能启用。
~/Desktop # 英文系统
~/桌面 # 中文系统用户本地的应用程序快捷方式目录。更改文件不需要 sudo 权限。
~/.local/share/applications系统范围的桌面图标目录。更改文件需要 sudo 权限。
/usr/share/applications总结一下如果想为普通用户创建应用图标可以优先将 .desktop 文件放在前两个路径下不需要 sudo 权限。另外路径1是将图标放在系统的桌面也就是开机后看到的界面上路径2则是放在菜单中点击 All 展开后可以看见图标。
.desktop文件的基本格式如下
[Desktop Entry]
Version1.0
TypeApplication
NameMy App
CommentThis is my application
Exec/usr/bin/my-app
Iconmy-app-icon
Terminalfalse
CategoriesUtility;字段含义Type类型如Application应用程序、Link超链接、Directory目录等Name应用程序显示名称GenericName泛称如“文本编辑器”Comment简短描述鼠标悬停提示用Exec启动命令可以包含参数如%f,%u见下方Icon图标文件名可为绝对路径或主题中的图标名Terminal是否在终端中运行 (true或false)Categories所属菜单类别如Utility,Development,Game等MimeType支持的 MIME 类型用于与文件类型关联StartupNotify是否启用启动通知通常为truePath启动程序前切换到的工作目录可选Hidden若为true则不会出现在菜单中
Exec 指定应用的路径通常是启动可执行文件/ sh 脚本路径/appimage路径。当然也可以是某个终端命令可以给自己常用的 shell 命令创建一个图标。
接下来讨论给 deb/appimage 快速创建图标的方法顺便提供一个可以给一般的可执行文件/sh脚本/shell命令创建图标的通用方法。
一、deb 应用
一般命令行安装 deb 都会自动创建应用图标。
命令是否自动处理依赖是否联网下载依赖sudo dpkg -i xxx.deb否否sudo apt install ./xxx.deb是是
如果没有则需要找到启动文件参考第三种方法创建图标。
二、appimage 应用
一种方法是把 appimage 看成是可执行文件手动编写 desktop 文件。更加高效的方法是安装 appimaged自动维护特定目录下所有 appimage 的桌面图标。
appiamged 项目说明 https://github.com/probonopd/go-appimage/tree/master/src/appimaged#appimaged
安装
# Remove pre-existing conflicting tools (if any)
systemctl --user stop appimaged.service || true
sudo apt-get -y purge appimagelauncher || true
[ -f ~/.config/systemd/user/default.target.wants/appimagelauncherd.service ] rm ~/.config/systemd/user/default.target.wants/appimagelauncherd.service# Clear cache
rm $HOME/.local/share/applications/appimage*# Optionally, install Firejail (if you want sandboxing functionality)# Download
mkdir -p ~/Applications
wget -c https://github.com/$(wget -q https://github.com/probonopd/go-appimage/releases/expanded_assets/continuous -O - | grep appimaged-.*-x86_64.AppImage | head -n 1 | cut -d -f 2) -P ~/Applications/
chmod x ~/Applications/appimaged-*.AppImage# Launch
~/Applications/appimaged-*.AppImage卸载方法
systemctl --user disable --now appimaged.service || true
rm ~/.config/systemd/user/appimaged.service
rm ~/.local/share/applications/appimagekit*.desktop
rm ~/Applications/appimaged-*-x86_64.AppImage注意安装后不要删除 ~/Applications/appimaged*.AppImage之后会自动检测以下路径中的 appimage 应用并自动创建图标。
安装后以下路径中的 appimage 应用都能被识别自动创建图表
/usr/local/bin/opt~/Applications建议把所有 appimage 应用如微信、QQ都放在这个路径下进行统一管理~/.local/bin~/Downloads$PATH, which frequently includes /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin, and other locations
例如将文件保存在 ~/Applications 图标会自动出现可以右键图标进一步固定到 Dock。如果文件被删除图标也会自动消失完全不需要手动管理。 三、通用方法
适用于一般的脚本、命令。
使用这个 desktop_creator.py 脚本
#!/usr/bin/env python3import sys
import os
from PyQt5.QtWidgets import (QApplication, QWidget, QLabel, QLineEdit, QPushButton,QFileDialog, QVBoxLayout, QHBoxLayout, QMessageBox, QCheckBox
)
from pathlib import Pathclass ShortcutCreator(QWidget):def __init__(self):super().__init__()self.setWindowTitle(快捷方式生成器)layout QVBoxLayout()# 应用名输入self.name_input QLineEdit()self.name_input.setPlaceholderText(请输入应用名称)layout.addWidget(QLabel(应用名称:))layout.addWidget(self.name_input)# 脚本路径输入script_layout QHBoxLayout()self.script_input QLineEdit()self.script_input.setPlaceholderText(选择启动脚本路径)script_button QPushButton(选择脚本)script_button.clicked.connect(self.select_script)script_layout.addWidget(self.script_input)script_layout.addWidget(script_button)layout.addLayout(script_layout)# 图标路径输入icon_layout QHBoxLayout()self.icon_input QLineEdit()self.icon_input.setPlaceholderText(选择图标路径)icon_button QPushButton(选择图标)icon_button.clicked.connect(self.select_icon)icon_layout.addWidget(self.icon_input)icon_layout.addWidget(icon_button)layout.addLayout(icon_layout)# 终端复选框self.terminal_checkbox QCheckBox(启动时打开终端)self.terminal_checkbox.setChecked(True)layout.addWidget(self.terminal_checkbox)# 快捷方式按钮button_layout QHBoxLayout()desktop_btn QPushButton(创建桌面快捷方式)global_btn QPushButton(创建应用快捷方式)desktop_btn.clicked.connect(self.create_desktop_shortcut)global_btn.clicked.connect(self.create_user_launcher_shortcut)button_layout.addWidget(desktop_btn)button_layout.addWidget(global_btn)layout.addLayout(button_layout)self.setLayout(layout)def select_script(self):path, _ QFileDialog.getOpenFileName(self, 选择启动脚本, , 脚本文件 (*.py *.sh *.AppImage);;所有文件 (*))if path:self.script_input.setText(path)def select_icon(self):path, _ QFileDialog.getOpenFileName(self, 选择图标, , 图标文件 (*.png *.ico *.svg *.xpm);;所有文件 (*))if path:self.icon_input.setText(path)def get_desktop_path(self):# 支持 Desktop 和 桌面possible_names [Desktop, 桌面]for name in possible_names:path Path.home() / nameif path.exists():return path# fallback: 尝试 xdg-user-dirxdg_path os.popen(xdg-user-dir DESKTOP).read().strip()return Path(xdg_path) if xdg_path else Path.home()def create_desktop_file(self, target_path):name self.name_input.text().strip()script_path self.script_input.text().strip()icon_path self.icon_input.text().strip()open_terminal self.terminal_checkbox.isChecked()if not (name and script_path):QMessageBox.warning(self, 错误, 请填写应用名称并选择启动脚本路径)returndesktop_entry f[Desktop Entry]
Name{name}
Exec{script_path}
Icon{icon_path if icon_path else utilities-terminal}
Terminal{true if open_terminal else false}
TypeApplication
CategoriesUtility;
try:with open(target_path, w) as f:f.write(desktop_entry)os.chmod(target_path, 0o755)QMessageBox.information(self, 成功, f已创建快捷方式{target_path})print(f✅ 快捷方式已生成: {target_path})print(f️ 若需删除运行命令rm {target_path})except Exception as e:QMessageBox.critical(self, 错误, f创建失败{e})def create_desktop_shortcut(self):desktop_path self.get_desktop_path()target desktop_path / f{self.name_input.text().strip()}.desktopself.create_desktop_file(str(target))def create_user_launcher_shortcut(self):app_path Path.home() / .local/share/applicationsapp_path.mkdir(parentsTrue, exist_okTrue)target app_path / f{self.name_input.text().strip()}.desktopself.create_desktop_file(str(target))if __name__ __main__:app QApplication(sys.argv)window ShortcutCreator()window.show()sys.exit(app.exec_())
安装依赖
pip3 install PyQt5运行脚本
cd desktop-creator
./desktop_creator.py输入应用名启动脚本路径应用图标路径还有选择是否打开终端。两个路径可以直接输入也可以点击右侧按钮进行选择。 输入完成后点击创建桌面快捷方式生成文件到 ~/Desktop。 右键选择 Allow Launching 之后可以双击运行应用
可以在终端中查看生成 desktop 文件的路径和删除方式。
同样可以点击创建应用快捷方式生成文件到 ~/.local/share/applications。