def format_(what, val):
    """
        Handles freedesktop's entry spec exec format modifiers
        As described in the desktop entry spec:
        http://standards.freedesktop.org/desktop-entry-spec/latest/ar01s06.html
    """
    safely_removed = ['%k', '%c', '%i']
    for key in safely_removed:
        what = what.replace(key, '')
    all_keys = ['%f', '%u', '%F', '%U']
    multi = ['%F', '%U']
    for key in all_keys:
        if key in what:
            if key not in multi:
                val = val.split()[0]
            return what.replace(key, val)
    return what
