Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Drag and drop text clippings to run Terminal commands UNIX
This is one I stumbled upon by complete accident: Text clippings can be dragged and dropped into a Terminal window to run a succession of commands.

To run a single command, the text clipping needs to include the command and a trailing carriage return. Multiple commands may be run in succession by separating them with carriage returns, and following the last command with a trailing carriage return.

[robg adds: At first I thought this tip referred to dragging and dropping text from one app to another, which we've covered here quite a few times in the past. However, it's referring (I believe) to the actual text clipping file you get if you, for instance, drag a snippet of text to the desktop. You can then drop that icon into a Terminal window to execute the commands it contains. You can use semicolons to separate commands on one line, and a backslash-carriage return to continue one command on a new line. I tried it with a simple ls -al; top -u 10[CR] that I created in TextEdit, and it worked as described.]
    •    
  • Currently 1.50 / 5
  You rated: 3 / 5 (4 votes cast)
 
[5,307 views]  

Drag and drop text clippings to run Terminal commands | 2 comments | Create New Account
Click here to return to the 'Drag and drop text clippings to run Terminal commands' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Drag and drop text clippings to run Terminal commands
Authored by: ScienceMan on Nov 07, '07 08:27:25AM

This has been wel known for a long time. It is one of the most trivial applications of text drag-and-drop capabilities.

What we really need is for one of the many multi-clipboard applications to develop the capability to store sequences of such commands in a queue and execute them one at at time upon invocation of a hot key, automatically advancing to the next command in the list upon each invocation of the hot key. This would make preparation of demos, etc., much easier than manual selection, cut and paste, and much better than one-shot invocation of a long list of commands by this method.



[ Reply to This | # ]
Drag and drop text clippings to run Terminal commands
Authored by: alys on Nov 08, '07 01:01:15AM

It's easy enough to do what you're suggesting with a very simple shell script. First, put all the commands into a plain text file (not RTF or any word processor format!), with one command on each line. Then, in between each command, insert a line that contains only the word "read". For example:

ls
read
echo "This is a message."
read
cat any_file.txt

"read" is a unix command that asks the user for input. The input must end with the return key, but you don't have to type anything before hitting return. This means that after each command executes, the shell script will wait until you have hit return before it continues. If you want some feedback to tell you when to hit return, you can do this:

ls
echo "Hit return to continue"
read
echo "This is a message."
echo "Hit return to continue"
read
cat any_file.txt



[ Reply to This | # ]