In Linux, is there a way to ask any xdg services, or gtk services, which application is the default application for a given file?
I realize that xdg-open will in fact, launch the correct application. However, I want to be able to display the application’s name in a context menu. So that when the user clicks on the menu item, it will then launch xdg-open, which will launch that app.
On OSX I can use LaunchServices for this:
def getDefaultDarwinApplication(path):
import LaunchServices
import CoreData
import urllib
url = CoreData.CFURLRef.URLWithString_("file://"+urllib.quote(path))
os_status, app_ref, appurl = LaunchServices.LSGetApplicationForURL(url, LaunchServices.kLSRolesAll, None, None)
if os_status != 0:
return ""
apppath = app_ref.as_pathname()
name = os.path.basename(apppath).replace(".app", "")
return name
The hope is that there is something similar on Linux I can use. A builtin python module would be best, but even screen scraping would work.
Even better I found the official gnome way to do this.