Skip to content

Instantly share code, notes, and snippets.

@rashkur
Created September 7, 2014 19:59
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save rashkur/46ce0d3a21471bc974fe to your computer and use it in GitHub Desktop.
Save rashkur/46ce0d3a21471bc974fe to your computer and use it in GitHub Desktop.
chrome icon fixer
import ConfigParser, mmap
config_file = "/usr/share/applications/google-chrome.desktop"
add_string_to_each_section = ["StartupWMClass", "Google-chrome-stable"]
option = add_string_to_each_section[0]
value = add_string_to_each_section[1]
class Fixer:
def check(self, cf, option, value):
f = open(cf)
s = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
if s.find(option+" = "+value) != -1:
print "already fixed"
exit(1)
def fix(self, cf, option, value):
Config = ConfigParser.ConfigParser()
Config.optionxform=str
Config.read(cf)
cfgfile = open(cf,'w')
for section in range(len(Config.sections())):
Config.set(Config.sections()[section], option, value)
Config.write(cfgfile)
cfgfile.close()
if __name__ == "__main__":
F = Fixer()
F.check(config_file, option, value)
F.fix(config_file, option, value)
@incognia
Copy link

incognia commented Dec 1, 2014

Thanks!

@e00dan
Copy link

e00dan commented Jan 22, 2015

This is a Python script. Run it using:

sudo python chromefix.py

(It's not obvious)

@dispeakble
Copy link

Thanks!

@TheDangy
Copy link

TheDangy commented Apr 8, 2015

@kuzirashi - Thanks for the comment, it helped me!

@zaigham
Copy link

zaigham commented May 6, 2015

Thanks for the script. 👍

@TheJoshGriffith
Copy link

This doesn't work for me, for some reason. Looks like an issue where the config has spaces inserted either side of the equals, which for some reason either Docky or Chrome or my DWM / DE doesn't like. I'm using Kubuntu with latest stable chrome, and removing the spaces does make it work. Any suggestions from OP? I did try this but it didn't work:

with open(config_file, 'r') as file:
        filedata = file.read()

filedata = filedata.replace(' = ', '=')

with open(config_file, 'w') as file:
        file.write(filedata)

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