Read current terminal - windows

Is it possible to read what's currently displayed on the windows terminal pragmatically using any available API?
For example, I've got an app that tail's some log files. I'd like to be able to hit a key and open a text editor at the line that is currently being viewed. The problem is the terminal also has scroll bars.

Not easy. Perhaps you could capture the screen and use OCR to identify its contents, or make a shortcut to some sort of macro that selects all the screen and copies the text. But there is no API available to perform the task you ask.
Of course, you can tee the command you're running in the console to a file, and open such file with an editor whenever you like, however it will show the full output of the command and not the visible part. If you like more information on that topic, it is answered in SO - Displaying Windows command prompt output and redirecting it to a file
.

Related

Copy all text from Command Window programatically

This article shows the well-known way to manually copy text from a Command window.
I'm looking for a way to do this programmatically. How could the cmd script that is running select all the text in its output window, and write it to a file?
I've found tools to do a screen capture into a file, but that may miss output if it has scrolled out of view? I'm looking for a way to capture an unattended cmd script's output (without modifying the whole script to redirect every line to a file).
Possibly this could be done with the windows API by finding the cmd window, sending CTRL-A and CTRL-C keycodes, and then write the clipboard text to a file. A possible approach for clip2txt is presented in this post.
Is there any other approach that should be considered?

How to log commands that are run through command palette in Sublime Text 3

I know that commands can be logged by going to the console View -> Show Console and typing
sublime.log_commands(True)
However, the commands that are run through the command palette are not logged, it just shows:
command: show_overlay {"overlay": "command_palette"}
Is there a way to log the commands run through the palette?
There's not currently a way to log the commands that are being executed from the command palette, no. If I recall correctly, this was possible in older builds of Sublime, but around the time that the command palette gained the ability to accept input for commands like View Package File, it stopped working. That might be an offshoot of the mechanism that's used to trigger input handling in the command palette, but that's just a guess.
Normally a plugin could be used to track something like this because EventListener classes have events to tell you before and after commands execute. However, there's an open issue on the tracker regarding the command palette on triggering on_post_window_command which is likely caused by the same thing as the commands not showing up in the log.
Currently the only way to know what command and arguments are being invoked from the command palette is to introspect the sublime-commands file that's providing them.
Unlike menus, commands in the command palette are not allowed to have dynamic captions, so it's a relatively simple matter to find the command entry that has a "caption" for the text you know you're picking.
The tricky part can be in determining where the command is coming from. In the console, sublime.find_resources('*.sublime-commands') will show you a list of every known command file, and you can open them via View Package File in the command palette.
Generally, anything that ships with Sublime is in Default/Default.sublime-commands, and anything that's added by a package is prefixed by the name of the package that added it, which can aid in determining what file to check.
Note that there are some commands in the command palette that are added by Sublime and don't come from a command file; commands that insert snippets and commands that change the syntax. Those are determined on the fly since the list of syntaxes and snippets is subject to change.

How to access Print dialog's 'Open PDF in Preview' in os x programmatically

I am building a Delphi application which opens an image and its metadata and prints it. For the Windows version I build a form to generate the PrintPreview, but in Mac I can use the Print Dialog's 'Open PDF in Preview' instead. When I click on it, a PDF file is generated and I can see it, its OK. The problem is I want to access this option directly from a button, so when the button is clicked, the PDF in Preview is opened and the user does not have to open the Print Dialog, then click the 'PDF' and then select 'Open PDF in Preview'. How can I do this?
I read about using Automator, apple scripts etc, but I still can't find it.
Is there any path this generated PDF Preview is stored, so maybe I can open it from there?...
TIA
Possible duplicate of Using Automator or Applescript or both to recursively print documents to PDF but I'll answer anyways.
To answer your question directly see the question I linked to. Basically you need to use System Events from applescript to accomplish that exactly
However, there's a quicker solution using /usr/sbin/cupsfilter. Check the man page for more.
You can call cupsfilter <an-image-file> and you'll get a PDF on stdout, courtesy of OSX's printing daemon. It looks quite configurable but I just learned about it a while ago.
If you want this to open for the user you can save it in a nice place or you can do it the one-shot way and do cupsfilter <your-image> | open -f -a "Preview" to open the PDF right up.

VS Console window does not show all results

I am using VS express 2012 to run a code that display content of many files. I found that first files content do not show and when I debug step by step I found that the content show on the console window and disappear when other results show, which means they get pushed out of the window. of course I scroll up and I find the latest files only not all. Is there any option control this feature? and how can I see all results?
To avoid this you should convert your console application to a Windows Forms one and put all the output on a TextBox. Just execute the command on the Form load and redirect all the output to the TextBox.
It's not much work IMHO.
This is the nature of a console application, no different than if you were to echo data to the Windows command prompt. If there is too much data then of course it will scroll off the visible screen.

Visual Frame Around Command Line Application

I am writing a command line application in Ruby using GLI. My app uses the Bio gem to query PubMed and print out bibliographic information for the results, one by one, to the terminal. The user is prompted for a small amount of information using HighLine, this is recorded to a database, and the display cycle repeats. Here is example output:
I would like to create a frame around my application as it runs to show the key bindings for exit, help commands etc. The text editor nano provides an example:
How can I create a similar frame around my program output, while allowing scrolling within that frame? Is there a cross-platform way to do this? I'd like to handle both Windows and *nix.

Resources