-1

Here's a custom key binding I have in ST3:

{ "keys": ["super+shift+e"], "command": "open_dir", "args": {"dir": "$file_path", "file": "$file_name"} }

I would like to edit/view the command functions referenced in this JSON key binding (e.g. open_dir, which opens Finder). I want to see the code behind open_dir to see how it works.

The JSON file of this key binding is Default (OSX).sublime-keymap. I've done file searches in ~/Library/Application Support/Sublime Text 3/ as well as in Applications/Sublime Text/ for command names such as open_dir but I still can't find the code of the commands that the JSON script is referencing.

Is there a way to find and view the commands that the JSON script is referencing?

EDIT: Thanks and apologies to those who commented before I made this edit. I've changed the title and the question text pretty heavily to try to be clearer since the post got put on hold.

colossatr0n
  • 2,215
  • 1
  • 12
  • 18
  • Can you put some code here? (i.e `your-json-file.json` and `your-python.py`. – Frank AK Nov 29 '17 at 05:44
  • A JSON file is not executable by itself, so unless you're using something else to interpret the JSON file, and do something with the contents, no. – roelofs Nov 29 '17 at 05:44
  • 1
    You could write a python function that parses the JSON object and then creates an subprocess based on the value of a key. – MyCah Nov 29 '17 at 05:50
  • Trying to have JSON call Python is like trying to have your shopping list load your groceries into your car; JSON doesn't *do* things. – user2357112 Nov 29 '17 at 05:50
  • @FrankAK I edited my main post to include relevant information about what exactly I'm trying to do. – colossatr0n Nov 29 '17 at 06:59
  • Sublime probably loads all builtin functions, then calls something like `eval("open_dir")` – OneCricketeer Nov 29 '17 at 07:10

2 Answers2

1

JSON is parsed, not interpreted. Plus they are not executable, much like a plain text file.

Therefore, you use python as normal to run a subprocess, but from a parsed value rather than a hard coded command

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
0

Its a bit unclear from your question what your end goal really is. You should provide some examples.

If you are looking to parse JSON data, extracted from a file, and execute in the terminal, then using the subprocess is likely the way to go.

Calling an external command in Python

cybergoof
  • 1,407
  • 3
  • 16
  • 25