Giter VIP home page Giter VIP logo

mimeopen's Introduction

mimeopen

open a file with file mimetype

this library is used when I design a desktop applicaiton in a company. I need to let the user choose an editor to open a file.

current the library just support windows, mac, and ubuntu(linux).

Be care that the lib just test on ubuntu linux. for other platform not guarantee. if you meet good idea, you can tell me.

install

you can clone this repository, and then install it from source:

python setup.py install

usage

it's very simple:

mimeopen filename

# or

from mimeopen import mimeopen

implementation

ubuntu

1. get the open with list from:

  • ~/.local/share/applications/mimeapps.list
  • /usr/share/applications/defaults.list

2. you can get all apps from /usr/share/applications

after you find the file type associations, you can find the application information inside the .desktop file.

windows

on window all the program information is saved in the registry, so just check the registry to find out the program information.

1. the HKEY_CLASSES_ROOT contains information merged from the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE, you can find the all the program can deal with ext.

2. if you want to set the default program for the current user, you can set the program id for the UserChoice under HKEY_CURRENT_USER\Software\Microsoft\Windows\Explorer\FileExts\ext\UserChoice

3. if you want to open with a program id, you can just use the program id to get the program shell command to open the program.

you may keep care that on windows there are default edit and default open program for a file type. If you want to set the default edit program for a file type, you need first find out the progid and then find out the program execute path, first associate the file ext with a progid by set HKEY_CURRENT_USER/Software/Classes/ext default value to progid, after that just create HKEY_CURRENT_USER/Software/Classes/Progid/shell/edit/command key and set the program path appending %1 for it.

mac

mac is more easy than you think, you can just query the system /Applications folder. then for each application it contains a .plist file to record the file extention it can deal with, so just read it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.