Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a following script that I have been using for years to paste selection or a whole line from TextWrangler to R. I got it from some website, slightly modified, and it has worked perfectly:

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 "R64"
cmd the_selection
end tell

Now I wanted to do the same, but pasting to Terminal window instead of R. However, when I modify the relevant line (3rd line from end) of the above script to:

tell application "Terminal"

the script no longer works. After some debugging I narrowed down the problem to the "cmd the_selection", where the editor says "Syntax error: Expected end of line but found identifier.". The funny thing is I cannot find what "cmd" command does - it's not in Apple's guidelines, and googling it doesn't help. I assume this must be some deprecated function to paste selection or line and that it no longer works in my version of applescript.

Any ideas how to fix this? cheers yot

share|improve this question
up vote 1 down vote accepted

Was cmd from R64's AppleScript dictionary or something?

You can run a command in Terminal with the do script verb.

tell application "Terminal"
    do script with command the_selection in window 1
end tell
share|improve this answer
Well isn't it nice! It worked right away. Thanks! – yotiao May 30 '12 at 8:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.