0

I have read some questions and answers regarding the behavior and some potential solutions to the following issue: When calling gsettings set to update the launcher, even though the command succeeds, the launcher doesn't always update.

My take on this is that as part of my installation, the call to

sudo -u {user} gsettings set com.canonical.Unity.Launcher favorites "{new launcher setting}"

does set the value, but the actual launcher doesn't update until I run something like

gsettings set com.canonical.Unity.Launcher favorites "$(gsettings get com.canonical.Unity.Launcher favorites)"

in the shell.

However, when I run my uninstall.sh script which makes all the same calls, and removes my launchers from the favorites, then the icons disappear.

So

sudo bash install.sh  # Installs but doesn't alter the launcher display
sudo bash uninstall.sh  # Uninstalls and does alter the launcher display

So I don't understand this inconsistency in behavior.

  • It would be helpful if you posted the contents of your install.sh and uninstall.sh scripts, so that we can understand what happens. – Malte Skoruppa Aug 31 '15 at 22:12
  • True. I played around with this a fair amount more, and I decided to split the operations of creating the .desktop files from the operation to update the gsettings. In addition, I moved the sudo from the outside, as in requiring the install/uninstall to be run using sudo, to embedding sudo in the script for those portions of the script that need sudo privileges. – sibex9591 Sep 1 '15 at 2:51
  • Why would you run gsettings as root for user changes? – doug Sep 1 '15 at 17:21
  • Originally, my install script was running as root, and to add the launcher icons for the running user of the I had to run those with sudo. – sibex9591 Sep 3 '15 at 18:58
0

I take back everything I said. I cut down my script to what is listed below, and in getting this to behave like I had described I hit upon that at the time that my .desktop files were created, the referenced contents of the Exec referenced command hadn't been created yet, so technically my .desktop file was invalid. This became apparent when I changed the Exec command below to 'date'. :) That is a consistent story.

#!/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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.