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

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