0

Let's say I have a file called hello.py.

# File: ~/hello.py
print('Hello')
print('Stack Exchange')

I would like to get a screencapture of hello.py when opened in vim editor as the ~/hello.png.

Need
Needed is a script called highlighter.sh which can do this.

bash highlighter.sh hello.py # should give hello.png with 
                             # syntax highlight
# For example when we open hello.py in vim
# It gives syntax-highlighted code, I need
# screencapture of this tab or window.
# In the end of command these tab or window should be closed.

Usage

We will have syntax highlighted png files for all the scripts which we can quickview in Mac.

Updates so far

Open the terminal # or, cd ~
vi hello.py
cmd t # opens new tab
screencapture -l$(osascript -e 'tell app "Terminal" to id of window 1') hello1.png  # this captures this command, not the screen of vim tab.

Related links:
https://github.com/thismachinechills/pyscreencapture
https://github.com/vorgos/QuickGrab
https://github.com/smokris/GetWindowID
Take a screenshot of the top-most window

  • 1
    Is the some reason you cannot just use the macOS builtin keyboard shortcut and take a screenshot of the Terminal window? For example: Shift-Command-4-Space > mouse over the target window and click or press Enter – user3439894 Aug 19 '18 at 15:01
  • 1
    The intent may be to generate a screenshot programatically, such as from a script, rather than requiring user input. – da4 Aug 19 '18 at 15:19
1

By combining the built-in screencapture with osascript -e you should be able to perform the following:

screencapture -l$(osascript -e 'tell app "Terminal" to id of window 1') hello1.png

If you have more than one Terminal window currently open you'll need to adjust the windowID value.

  • Thanks, but It captures the tab of terminal running this given command, not the tab running VIM, and also does not close the tab with vim . – astro123 Aug 19 '18 at 15:49
  • You should update your original question to indicate that you'd like to capture a specific tab in Terminal, not window, and that you'd like your intended command to also close the window/tab. In my testing I was able to run this command from a separate window as well as from a new shell after SSHing in and capture the contents as originally stated. – da4 Aug 23 '18 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .