MacOS – Sending commands from TextWrangler to the terminal

applescriptkeyboardmacosterminaltextwrangler

I want to send commands from TextWrangler to the terminal. Even if I found this, I don't understand how that works since I'm brand new to Unix and running Applescripts.

tell application "TextWrangler"
    set the_selection to (selection of front window as string)
    if (the_selection) is "" then
        set the_selection to line (get startLine of selection) of front window as string
    end if
end tell

tell application "Terminal"
    do script with command the_selection in window 1
end tell

I saved an Applescript that looks like this:
enter image description here

Now, what I think is to put the script in the TextWrangler Scripts Folder:
enter image description here

  1. But then, how do I send commands to the Terminal.app?
  2. How can I press cmd + enter to send a line from TextWrangler to the Terminal?

Best Answer

You must put the script in the "/Users/yourName/Library/Application Support/TextWrangler/Scripts" folder

After that:

  • Open the preferences of the TextWrangler
  • Select "Menus & ShortCuts" --> "Scripts" --> "your script" to add your shortcut to the script
  • TextWrangler accept the (cmd + enter) keys as shortcut enter image description here