我已经阅读了一些有关该行为的问题和答案以及以下问题的一些潜在解决方案:当调用gsettings set
更新启动器时,即使命令成功,启动器也不会总是更新。
我对此的看法是,作为我的安装的一部分,
sudo -u {user} gsettings set com.canonical.Unity.Launcher favorites "{new launcher setting}"
确实设置了值,但实际的启动器直到我运行类似
gsettings set com.canonical.Unity.Launcher favorites "$(gsettings get com.canonical.Unity.Launcher favorites)"
在壳中。
然而,当我运行我的uninstall.sh
脚本时,该脚本会进行所有相同的调用,并从收藏夹中删除我的启动器,然后图标就会消失。
所以
sudo bash install.sh # Installs but doesn't alter the launcher display
sudo bash uninstall.sh # Uninstalls and does alter the launcher display
所以我不明白这种行为上的不一致。
答案1
我收回我说的所有话。我将脚本缩减为下面列出的内容,在让它按照我描述的方式运行的过程中,我发现在创建 .desktop 文件时,Exec 引用命令的引用内容尚未创建,因此从技术上讲我的 .desktop 文件无效。当我将下面的 Exec 命令更改为“date”时,这一点变得显而易见。:) 这是一个一致的故事。
#!/usr/bin/env bash
COMMAND=$(basename $0 .sh)
SS_ROOT=$(pwd)
DESKTOP_SS=/usr/share/applications/eiospa.desktop
DESKTOP_EIO=/usr/share/applications/eioadmin.desktop
TEMPDIR=$(mktemp --directory -q)
#
# Return settings value with extra shit stripped away
#
getSettings()
{
local schema=${1}
local key=${2}
local settings=$(gsettings get ${schema} ${key} | sed -e 's/[,'\'']//g')
settings=${settings#[}
settings=${settings%]}
echo "${settings}"
}
#
# Add back the extra shit and update the settings
#
setSettings()
{
local schema=${1}
local key=${2}
local settings="['$(echo ${3} | sed -e 's/ /'\'', '\''/g')']"
gsettings set ${schema} ${key} "${settings}"
}
#
# Add any provided favorite that isn't in the settings already
#
addFavorite()
{
#local favorite=${1}
local settings=$(getSettings "com.canonical.Unity.Launcher" "favorites")
local found=0
for favorite in ${*}
do
for s in ${settings}
do
[ ${s} = ${favorite} ] && found=1
done
[ ${found} -eq 0 ] && settings="${favorite} ${settings}"
done
setSettings "com.canonical.Unity.Launcher" "favorites" "${settings}"
}
#
# Remove provided favorites if they are in the settings
#
removeFavorite()
{
local favorite=${1}
local settings=$(getSettings "com.canonical.Unity.Launcher" "favorites")
local newSettings=
local sep=
for favorite in ${*}
do
for s in ${settings}
do
[ ${s} = ${favorite} ] || {
newSettings="${newSettings}${sep}${s}"
sep=" "
}
done
settings=${newSettings}
newSettings=
sep=
done
setSettings "com.canonical.Unity.Launcher" "favorites" "${settings}"
}
createSSDesktop()
{
cat <<EOF4 >${TEMPDIR}/$(basename ${DESKTOP_SS})
[Desktop Entry]
Type=Application
Terminal=false
Name=EIO SPA
Icon=${SS_ROOT}/runtime/linux/icons/EIOSPA.ico
Exec=firefox http://localhost:8080
EOF4
sudo mv ${TEMPDIR}/$(basename ${DESKTOP_SS}) ${DESKTOP_SS}
}
createAdminDesktop()
{
cat <<EOF5 >${TEMPDIR}/$(basename ${DESKTOP_EIO})
[Desktop Entry]
Type=Application
Terminal=true
Name=EIO Admin
Icon=${SS_ROOT}/runtime/linux/icons/EIOAdmin.ico
Exec=date
EOF5
sudo mv ${TEMPDIR}/$(basename ${DESKTOP_EIO}) ${DESKTOP_EIO}
}
installLaunchers()
{
addFavorite 'application://eioadmin.desktop' 'application://eiospa.desktop'
}
uninstallLaunchers()
{
removeFavorite 'application://eioadmin.desktop' 'application://eiospa.desktop'
}
removeFiles()
{
sudo rm -f ${DESKTOP_EIO}
sudo rm -f ${DESKTOP_SS}
}
install()
{
createSSDesktop
createAdminDesktop
[ -n "${1}" ] && sleep ${1}
installLaunchers
}
uninstall()
{
uninstallLaunchers
removeFiles
}
case ${COMMAND} in
installex)
install $*
;;
uninstallex)
uninstall $*
;;
*)
;;
esac
rm -rf ${TEMPDIR}