Last active
August 29, 2015 14:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
explanation: http://askubuntu.com/a/522959/72216