Pasting commands from TextWrangler to Terminal (applescript troubleshooting)

applescriptcopy/pasteterminal

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

Best Answer

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