Keyboard Maestro macro to open .pickle file in IPython

I often want to view the contents of .pickle files on my computer. I like doing this in the IPython REPL, so I would manually open a new Terminal window, switch to my data science virtualenv, import pickle, and then load the .pickle file in question into a variable. Sounds like a prime target for automation, eh?

Here's a Keyboard Maestro macro that will take the selected .pickle file in Finder and open it up in IPython (inside iTerm2), assigning it to the variable x.

Here's what it looks like (the macro is triggered through LaunchBar with this custom action):

After the macro runs, I type in x to show the object in the Pickle file (in this case, it's just {"hello": "world"}.

Here's what the macro looks like in Keyboard Maestro:

Here's the code:

Note that this requires your Python virtualenv to be set up like this and you have to have a "data" virtualenv. If either of these things aren't true, you'll need to modify the shell commands in the AppleScript accordingly.