You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于获取“显示应用程序”按钮及Dash to Dock侧边栏中应用名称的技术问询

关于获取“显示应用程序”按钮及Dash to Dock侧边栏中应用名称的技术问询

Hey there! Great question—your initial approach of checking /usr/share/applications makes sense, but as you noticed, that directory includes every desktop app installed on your system (even hidden ones), which is why it’s way more than what shows up in "Show Applications" or Dash to Dock. Let’s break down how to get exactly the apps you’re looking for:

1. 获取“显示应用程序”网格中的所有应用名称

The apps in the "Show Applications" grid are the ones that aren’t marked as hidden. Desktop files can have a NoDisplay=true line to hide them from the app list. To filter out these hidden apps, we can use grep to find desktop files that don’t have this flag:

命令示例:

# 列出系统级可见应用
grep -L "NoDisplay=true" /usr/share/applications/*.desktop | xargs basename -s .desktop

# 列出用户级可见应用(比如你自己安装的非系统应用)
grep -L "NoDisplay=true" ~/.local/share/applications/*.desktop 2>/dev/null | xargs basename -s .desktop

解释:

  • -L in grep returns files that don’t contain the matching line ("NoDisplay=true").
  • basename -s .desktop strips the .desktop extension to get just the app name.
  • The 2>/dev/null in the second command suppresses errors if the user applications directory is empty.

2. 获取Dash to Dock侧边栏中的应用名称

Dash to Dock shows two types of apps: pinned apps (the ones you’ve manually added to the dock) and frequently used apps. Let’s cover both:

获取固定在Dock上的应用

GNOME stores pinned apps in its dconf database. You can retrieve them with gsettings, then parse the output to get clean app names:

gsettings get org.gnome.shell favorite-apps | tr -d "[]'," | xargs -I {} basename {} .desktop

解释:

  • gsettings get org.gnome.shell favorite-apps outputs a list like ['firefox.desktop', 'org.gnome.Nautilus.desktop'].
  • tr -d "[]'," removes the brackets, quotes, and commas to clean up the list.
  • basename {} .desktop again strips the .desktop extension for readable names.

获取Dash to Dock中的常用应用

Unfortunately, retrieving frequently used apps is a bit trickier—GNOME Shell tracks usage stats in dconf, but the data is stored in a less straightforward format. If you really need this, you can check the dconf key org.gnome.shell.app-switcher.pinned-apps (though this might not be exactly what Dash to Dock uses for frequent apps). Alternatively, you’d need to parse usage logs, which isn’t as clean as the pinned app command.

总结

  • Use the grep commands to get all visible apps in "Show Applications".
  • Use the gsettings command to get pinned apps in Dash to Dock.
  • Your original ls -l /usr/share/applications shows all desktop files, including hidden ones—hence the extra entries.

备注:内容来源于stack exchange,提问作者rtciv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 12:24:38