Skip to content

Instantly share code, notes, and snippets.

@mjgiarlo
Created June 6, 2010 00:16
Show Gist options
  • Save mjgiarlo/427124 to your computer and use it in GitHub Desktop.
Save mjgiarlo/427124 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os.path
import sys
TEMPLATE = """[Desktop Entry]
Encoding=UTF-8
Name=%(basename)s
Type=Link
URL=%(url)s
Icon=gnome-fs-bookmark
"""
def convert(f):
""" Takes a full filepath to a .URL file, converts it to a .desktop file
in the same directory """
print "Converting %s" % f
(filepath, filename) = os.path.split(f)
(basename, extension) = os.path.splitext(filename)
with open(f) as urlfile:
lines = [line.strip() for line in urlfile.readlines()]
url = lines[1].split('URL=')[1]
dtfname = os.path.join(filepath, '%s.desktop' % basename)
with open(dtfname, 'w') as dtfile:
print "Writing %s" % dtfile.name
dtfile.write(TEMPLATE % locals())
if __name__ == '__main__':
for arg in sys.argv[1:]:
if os.path.isfile(arg) and arg[-3:].lower() == 'url':
convert(arg)
else:
print "*** %s is not a URL file" % arg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment