TextExpander: Get Information from the Terminal
23 Dec 2013I seem to be having a bit of a spree on TextExpander posts at the moment looking at my last few posts - can you get too much of a good thing?. This time I’m going to be sharing some snippets I have for getting useful information from the Mac using some terminal commands.
As well as being able to insert boiler plate pieces of text and auto correct typographic errors, TextExpander can also execute and return output from scripts. This means that it isn’t too onerous to create a few simple scripts to be run from TextExpander that can then be automatically inserted by TextExpander.
To illustrate what I mean, let’s take a look at a generic script that executes a single command:
Label | Run Command |
Description | Run a terminal command from a specific shell. |
Abbreviation | .runcommand |
Content |
|
The first line establishes which shell will be used to execute the command. It uses a user prompt of a drop down menu of shell options, the default being bash. You could tailor this list to the shells you might wish to use. You could even remove the fill in option and simply specify a specific shell to use each time.
The second line prompts the user with a free form text box in which a terminal command can be entered. This is set as a single line, but could be changed to be a multi-line entry if you really wanted.
When the trigger (.runcommand) is entered, the dialog window will display and the output from the command that is entered will then replace it.
I have a number of other scripts that are based on this principle that I use to leverage the power of the command line without so much copy and pasting. The first pair I find useful when I need to e-mail on the results of some basic network checks.
Label | Run Ping |
Description | Output the result of a user specified number of pings to a user specified address (host name or IP). |
Abbreviation | .runping |
Content |
|
Label | Run TraceRoute |
Description | Run a network trace (route) on a user specified address (host name or IP). |
Abbreviation | .runtrace |
Content |
|
The next snippet allows me to quickly dump out some information about my Mac
Label | Get System Information |
Description | Run a set of terminal commands to output a set of useful information about your Mac. This might be the sort of information you pass on to a developer who is debugging an issue on your machine. |
Abbreviation | .runsysinfo |
Content |
|
Label | Run Cat (Manual) |
Description | Output the content of a user specified file. The user is prompted to enter the path to the file. |
Abbreviation | .runcat |
Content |
|
The final set of snippets allow me to output file contents and directory listings by passing in paths (to the respective file or directory). For each there are two flavours allowing you to pass the path either by manual entry or by clipboard. I find that maybe getting an initial path on the clipboard I’ll just do a direct from clipboard run and then for variations I’ll do a manual run and then paste and amend the first path.
Label | Run Cat (Clipboard) |
Description | Output the content of a user specified file. The path to the file is read from the clipboard. |
Abbreviation | .runcbcat |
Content |
|
Label | Run Listing (Manual) |
Description | Output a directory listing (long list format including directories starting with a '.'). The user is prompted to enter the path to the directory. |
Abbreviation | .runlist |
Content |
|
Label | Run Listing (Clipboard) |
Description | Output a directory listing (long list format including directories starting with a '.'). The path to the directory is read from the clipboard. |
Abbreviation | .runcblist |
Content |
|
You can also download and import these snippets as a group.
I’m sure many of you will have your own favourite terminal commands that you might find useful to capture the output from using TextExpander … and I’d love to know what they are. Why not leave a comment and share your favourite(s)?