Hang-hang theha mekhatlo e tloaelehileng ea lifaele

Litloaelano tsa li-file tse ikemetseng, ke hore, ho khetha lenaneo le tla bula faele ho tsoa ho Explorer/Finder. 'Me ke arolelana.

Mathata pele. Lifaele tse nang le li-extensions tse hlokahalang hangata ha li buloe ke ntho leha e le efe ka ho sa feleng, 'me haeba li buloa, joale ke iTunes. Tlas'a Windows, litloaelano tse hlokahalang ka linako tse ling li lahleha ka ho felletseng ha u kenya (kapa esita le ho nts'oa) mananeo: ka linako tse ling u notlolla GIMP, 'me lifaele tsa ico li nkuoa ho tsoa ho sebali se tloaelehileng sa faele ho ea Setsing sa Lifoto se tloaelehileng. Hobaneng? Molelmong oa eng? Ha ho tsejoe ... Ho thoe'ng haeba ke fumane mohlophisi e mocha kapa, ka mabaka a fapaneng, kemiso e ncha? Ho thoe'ng haeba ho na le likhomphutha tse fetang bonngoe? Ka kakaretso, ho tobetsa litoeba lipuisanong ke boithabiso bo joalo.

Ho e-na le hoo, ke bolokile lifaele tse peli ho Dropbox 'me joale ke khona ho khutlisetsa lefats'e la k'homphieutha ho tloaelehileng hoo e ka bang hang-hang. 'Me u emetse eng ka lilemo tse ngata hakaale ... E latelang ke recipe ea Windows le macOS.

Windows

Ho Windows console cmd.exe sena se etsoa ka mekhahlelo e 'meli:

ftype my_file_txt="C:Windowsnotepad.exe" "%1"
assoc .txt=my_file_txt

Liphetoho li etsahala hang-hang. Leha taba ea hore mokhatlo o ngolisitsoe bakeng sa mosebelisi ea itseng, ka mabaka a itseng litaelo tsena li hloka ho tsamaisoa joalo ka molaoli. Hape u se ke ua lebala ho habeli letšoao la peresente (%% 1) ha u matha ho tloha faeleng ea bat. Lefatše la boselamose la Windows 7 Ultimate 64-bit…

macOS

Ho MacOS ho bonolo ho theha mekhatlo e sebelisang lisebelisoa mosebetsi. E kentsoe ka brew install duti. Mohlala oa tšebeliso:

duti -s com.apple.TextEdit .txt "editor"

Liphetoho li qala ho sebetsa hang-hang, ha ho hlokahale sudo. Mona khang "com.apple.TextEdit" ke seo ho thoeng ke "bundle id" ea lenaneo leo re le hlokang. Khang ea "mohlophisi" ke mofuta oa mokhatlo: "mohlophisi" bakeng sa ho hlophisoa, "shebelli" bakeng sa ho shebella, "tsohle" bakeng sa ntho e 'ngoe le e' ngoe.

U ka fumana "id ea bongata" e kang ena: haeba ho na le "/Applications/Sublime Text.app" ea mofuta oa boraro, ID ea eona ea bongata e tla ba "com.sublimetext.3", kapa e 'ngoe:

> osascript -e 'id of app "Sublime Text"'
com.sublimetext.3

E lekoa ho macOS Sierra.

Mongolo oa ho qetela oa Windows (.bat)

@echo off

set XNVIEW=C:Program Files (x86)XnViewxnview.exe
set SUBLIME=C:Program FilesSublime Text 3sublime_text.exe
set FOOBAR=C:Program Files (x86)foobar2000foobar2000.exe

call :assoc_ext "%SUBLIME%" txt md js json css java sh yaml
call :assoc_ext "%XNVIEW%" png gif jpg jpeg tiff bmp ico
call :assoc_ext "%FOOBAR%" flac fla ape wav mp3 wma m4a ogg ac3

goto :eof

:assoc_ext
  set EXE=%1
  shift
  :loop
  if "%1" neq "" (
    ftype my_file_%1=%EXE% "%%1"
    assoc .%1=my_file_%1
    shift
    goto :loop
  )
goto :eof

Sengoloa sa ho qetela sa macOS (.sh)

#!/bin/bash

# this allows us terminate the whole process from within a function
trap "exit 1" TERM
export TERM_PID=$$

# check `duti` installed
command -v duti >/dev/null 2>&1 || 
  { echo >&2 "duti required: brew install duti"; exit 1; }

get_bundle_id() {
    osascript -e "id of app """ || kill -s TERM $TERM_PID;
}

assoc() {
    bundle_id=$1; shift
    role=$1; shift
    while [ -n "$1" ]; do
        echo "setting file assoc: $bundle_id .$1 $role"
        duti -s "$bundle_id" "." "$role"
        shift
    done
}

SUBLIME=$(get_bundle_id "Sublime Text")
TEXT_EDIT=$(get_bundle_id "TextEdit")
MPLAYERX=$(get_bundle_id "MPlayerX")

assoc "$SUBLIME" "editor" txt md js jse json reg bat ps1 cfg sh bash yaml
assoc "$MPLAYERX" "viewer" mkv mp4 avi mov webm
assoc "$MPLAYERX" "viewer" flac fla ape wav mp3 wma m4a ogg ac3

Source: www.habr.com

Eketsa ka tlhaloso