"Insert text by typing" doesn't work in the Terminal

This simple macro fails for me:

I get this:

Results are the same when I tell KM to paste instead of typing.

Looks like the macro is being executed twice. Check that you haven’t managed to get two copies of Keyboard Maestro Engine running. Check the Engine.log file (Help ➤ Open Logs Folder) to see what Keyboard Maestro thinks is happening.

Consider quitting Keyboard Maestro Engine and relaunching it.

Another case would be if you have a system keyboard shortcut that maps cdd (or a shortcut set up in another application like TextExpander). Double check that (if so, the shortcut would still work after you quit the Keyboard Maestro Engine).

1 Like

Hey Jack,

The Insert Text by Pasting action is probably the way to go.

Remove the “\n” if you don't want the command to be automatically completed.

Terminal - CD to Desktop.kmmacros (1.3 KB)

On the other hand telling the Terminal directly what to do is a bit more organic.

This will check to make sure the front terminal window isn't busy. If it IS busy then the command will open in a new window.

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2011/10/16 02:11
# dMod: 2017/02/24 02:19
# Appl: Terminal
# Task: CD to ~/Desktop
# Libs: None
# Osax: None 
# Tags: @Applescript, @Terminal, @CD, @Front, @Desktop
------------------------------------------------------------------------------

try
   
   tell application "Terminal"
      if (busy of front window) = true then
         
         do script "cd ~/Desktop"
         
      else if (busy of front window) = false then
         
         tell front window
            do script "cd ~/Desktop" in selected tab
         end tell
         
      end if
   end tell
   
on error eMsg number eNum
   tell me to display dialog eMsg & return & return & eNum
end try

------------------------------------------------------------------------------

Finally – the most organic method of doing this is by aliasing the command directly in the Terminal.

Paste this into the Terminal and hit enter.

alias cdd='cd ~/Desktop'

Then type: cdd<enter>

And watch the magic happen.

If you want to keep this command available you'll need to add it to your Terminal start-up file.

I use the $HOME.profile file myself:

~/.profile

If it doesn't exist you have to create it. Use BBEdit or TextWrangler (or another plain-text editor).

Watch out – as soon as you name the file it will dissapear into invisibility in the Finder – because all files/folders on Unix that start with a (dot) are invisible.

You can find out if any aliases are loaded in the current shell by entering the command:

alias<enter>

I myself have 45 of them (at current count).

See my post here for another useful script:

Open a new Terminal window for the current Finder folder

-Chris

2 Likes

@peternlewis I had it running in TextExpander still. I feel dumb! Thank you.

@ccstone Thank you! I had started to get this project (aliases done properly via my bash profile, as you suggested) started a while ago and forgot all about it. That is an even better method.

LOL, I have gone the opposite way, that is, transferred (many of) my Bash aliases to Typinator. I just love the search function – and to have all in one place…

1 Like

Grrf... I've done that a couple of times – don't feel too dumb.  :sunglasses:

I use Typinator for such things too, although I still like my Bash aliases and functions.

Here's a function to search your aliases:

# Search Aliases
function als()
{
alias | egrep -i "$1"
}

Usage would be:

als curl

Or if you want a multi-word search:

als 'curl.*remote.*name.*agent'

** Note the single-quotes.

If I wanted to get radical I could write a script to import the aliases into a group in Typinator, or refresh said group if it already existed.

-Chris

Hi Chris,

Thanks for the handy tips.

While that's fine and good, what I can do with Typinator is:

  1. Start to type my abbreviation, for example:
  • pbs
  1. Now, as often, I forgot the rest of the abbreviation – or I quickly want to see my options:
  1. I select, or continue typing, and hit Return.

Very comfortable :blush:

The other thing is that often I prefer to see my expansions before continuing:

If an abbreviation is set as ‘Whole word’ I can always choose:

  • Finish the abbreviation with Space → Abbreviation is expanded (and if needed I can add something)
  • Finish the abbreviation with Return → Abbreviation is executed

Hey Tom,

I'm fully aware of this and have been using Typinator since 2010. In fact I bought it specifically because of its excellent Quick Search feature (which you demonstrate above).

It is. But I still like my aliases and functions in the Terminal.  :sunglasses:

(Which doesn't mean that I don't have a gaggle of shell commands in a Typinator group.)

I have 75 rule-sets with all kinds of goodies in them and almost 50K text-expansions.

-Chris