Skip to content

Instantly share code, notes, and snippets.

@Jacob-Vlijm
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jacob-Vlijm/84632ab761b518b2f87b to your computer and use it in GitHub Desktop.
Save Jacob-Vlijm/84632ab761b518b2f87b to your computer and use it in GitHub Desktop.
script for Ubuntu+Unity to add an application( 's desktop file) to the launcher
#!/usr/bin/env python
"""
Copyright (C) 2014 Jacob Vlijm
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or any later version. This
program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details. You
should have received a copy of the GNU General Public License along with this
program. If not, see <http://www.gnu.org/licenses/>.
"""
import subprocess
import sys
desktopfile = sys.argv[1]
def current_launcher():
get_current = subprocess.check_output(
["gsettings", "get", "com.canonical.Unity.Launcher", "favorites"]
).decode("utf-8")
return eval(get_current)
def add_new(desktopfile):
curr_launcher = current_launcher()
last = [i for i, x in enumerate(curr_launcher) \
if x.startswith("application://")][-1]
new_icon = "application://"+desktopfile
if not new_icon in curr_launcher:
curr_launcher.insert(last, new_icon)
subprocess.Popen(
["gsettings", "set", "com.canonical.Unity.Launcher","favorites",
str(curr_launcher)])
else:
pass
add_new(desktopfile)
@Jacob-Vlijm
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment