当前位置: 首页 > wzjs >正文

北京 网站建设咨询顾问公司中国科技新闻网

北京 网站建设咨询顾问公司,中国科技新闻网,云南app开发公司哪家好,自己做网站投入Ubuntu 创建应用图标的方式汇总,deb/appimage/通用方法 对于标准的 Ubuntu(使用 GNOME 桌面),desktop 后缀的桌面图标文件主要保存在以下三个路径: 当前用户的桌面目录(这是最常见的位置)。所…

Ubuntu 创建应用图标的方式汇总,deb/appimage/通用方法

对于标准的 Ubuntu(使用 GNOME 桌面),desktop 后缀的桌面图标文件主要保存在以下三个路径:

  1. 当前用户的桌面目录(这是最常见的位置)。所有放在这个目录中的.desktop文件、文件夹或快捷方式会显示在桌面上(如果桌面图标功能启用)。
~/Desktop # 英文系统
~/桌面 # 中文系统
  1. 用户本地的应用程序快捷方式目录。更改文件不需要 sudo 权限。
~/.local/share/applications
  1. 系统范围的桌面图标目录。更改文件需要 sudo 权限。
/usr/share/applications

总结一下,如果想为普通用户创建应用图标,可以优先将 .desktop 文件放在前两个路径下,不需要 sudo 权限。另外路径1是将图标放在系统的桌面,也就是开机后看到的界面上,路径2则是放在菜单中,点击 All 展开后可以看见图标。

.desktop文件的基本格式如下:

[Desktop Entry]
Version=1.0
Type=Application
Name=My App
Comment=This is my application
Exec=/usr/bin/my-app
Icon=my-app-icon
Terminal=false
Categories=Utility;
字段含义
Type类型,如Application(应用程序)、Link(超链接)、Directory(目录)等
Name应用程序显示名称
GenericName泛称,如“文本编辑器”
Comment简短描述,鼠标悬停提示用
Exec启动命令,可以包含参数(如%f,%u,见下方)
Icon图标文件名(可为绝对路径或主题中的图标名)
Terminal是否在终端中运行 (truefalse)
Categories所属菜单类别,如Utility,Development,Game
MimeType支持的 MIME 类型(用于与文件类型关联)
StartupNotify是否启用启动通知(通常为true
Path启动程序前切换到的工作目录(可选)
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。如果文件被删除,图标也会自动消失,完全不需要手动管理。

请添加图片描述

三、通用方法

适用于一般的脚本、命令。

  1. 使用这个 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'}
Type=Application
Categories=Utility;
"""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()}.desktop"self.create_desktop_file(str(target))def create_user_launcher_shortcut(self):app_path = Path.home() / ".local/share/applications"app_path.mkdir(parents=True, exist_ok=True)target = app_path / f"{self.name_input.text().strip()}.desktop"self.create_desktop_file(str(target))if __name__ == "__main__":app = QApplication(sys.argv)window = ShortcutCreator()window.show()sys.exit(app.exec_())
  1. 安装依赖
pip3 install PyQt5
  1. 运行脚本
cd desktop-creator && 
./desktop_creator.py
  1. 输入应用名,启动脚本路径,应用图标路径还有选择是否打开终端。两个路径可以直接输入,也可以点击右侧按钮进行选择。

请添加图片描述

输入完成后,点击创建桌面快捷方式,生成文件到 ~/Desktop。

请添加图片描述

右键选择 Allow Launching 之后可以双击运行应用

可以在终端中查看生成 desktop 文件的路径和删除方式。

同样可以点击创建应用快捷方式,生成文件到 ~/.local/share/applications。

http://www.dtcms.com/wzjs/514212.html

相关文章:

  • 网站后台无编辑器腾讯营销平台
  • 铜仁市网站建设百度图片搜索网页版
  • 建立公司网站流程宣传网站站点最有效的方式是
  • 如何建设一个手机网站今日热搜榜排名
  • 做政府网站服务百度上广告怎么搞上去的
  • 独立建站平台百度指数 移民
  • 美国有哪些做促销的网站没经验可以做电商运营吗
  • 怎么查看网站外链效果温州seo品牌优化软件
  • 铜川做网站的公司苏州seo服务
  • 公众号链接的手机网站怎么做的某网站seo诊断分析
  • 网站制作从零开始搜索引擎营销案例分析题
  • 人妖怎么做的手术视频网站西安网络推广公司
  • 建站公司见客户没话说网页自动点击软件
  • 书城网站开发手机百度app最新版下载
  • 橙子建站是什么平台网站查询网
  • 网站充值页面模板推广网络推广平台
  • 网页模板哪个网站可以下载百度账号出售平台
  • c access做网站登录页面seo外链工具源码
  • 开发公司与物业公司交接清单seo外链优化
  • 上海设计装修公司排名seo查询官网
  • wordpress回收站在哪批量查询神马关键词排名
  • 企业网站长度知名seo公司
  • 说几个手机可以看的网站关键词分析工具有哪些
  • 17做网店这个网站做起多少钱网络推广是干什么的
  • dede查看网站沈阳网络seo公司
  • 学做网站php吗市场营销公司
  • 推广型网站开发软件网站优化检测
  • wordpress上删除主题济南seo网络优化公司
  • 西安家政公司网站建设宁波网站推广公司价格
  • 利用webflow建网站关键词工具