View Full Version : Entering text into Terminal
t.b.b.
08-14-2010, 12:05 PM
Wohoo, first post! Got to ask for some help this time. Hope to offer some soon.
I am trying to enter text into a Terminal session. I've spent an hour looking and can't find it anywhere.
Thanks!
t.b.b.
hayne
08-14-2010, 12:33 PM
You need to describe your task in more detail.
What text do you want to enter?
Is there a program already executing in that Terminal? (which program?)
Etc
t.b.b.
08-14-2010, 01:27 PM
I want to enter a command: workon popeye
I would like it to start a terminal session and then enter this line of text followed by a carriage return.
I got as far as:
tell application "Terminal"
activate
end tell
Any text I enter after the "activate" command is ignored, quoted or not.
fracai
08-14-2010, 01:45 PM
What does "workon" do?
If it opens another application (non-Terminal), you could simply use:
do shell script "workon popeye"
If you want to actually see the results of the command in the Terminal window, you could skip the AppleScript and simply create a file containing something like this:
#!/bin/sh
workon popeye
Save it as workon-popeye.command, make it executable ( chmod +x workon-popeye.command ), and run it by double clicking the file from the Finder.
Knowing what "workon" does might help pinpoint the right solution for you.
DeltaMac
08-14-2010, 01:49 PM
I want to enter a command: workon popeye
Is Popeye the chess problem-solving app?
or something else?
What do you expect the 'workon' to do - what is your goal?
t.b.b.
08-14-2010, 01:55 PM
workon popeye is a command telling the shell to launch a virtual environment name popeye.
I can type this command at the prompt and it works, so I should be able to get AppleScript to do this. Seems pretty simple, right? I hope so! :0
t.b.b.
08-14-2010, 02:09 PM
I figured it out:
tell application "Terminal"
activate
do script "workon popeye
cd popeye
./merchant_manage.py runserver 8020"
end tell
As you can see, I wanted it do more than just run that one command, and this script works on all three commands, even only one is a shell script command - the others are a python command and the other a change directory command...
-------------------
Now I have to figure out how to tell Terminal to open a new window and run some more commands ... does anyone know how to do that?
Terminal.app applescripting has always been buggy. if you want to do some serious applescripting of shells you'd do better to use iTerm (http://iterm.sourceforge.net/) - freeware terminal emulator.
what I'm not understanding, however, is what you're trying to do (and whether it's even legal). the only google reference I can find for this is trying to get Nintendo games to run on a virtual console - something I doubt Nintendo approves of as a general principle - but if your goal is to get a game up and running I don't understand why you're futzing around in terminal when you could simply script it directly from applescript.
unless you want to clarify your goals, there's not much we can do to point you in the right direction.
t.b.b.
08-14-2010, 02:52 PM
what I'm not understanding, however, is what you're trying to do (and whether it's even legal).
LOL! I am using a Django based system for managing a website. We use vitual environments in order to sequester the different aspects of the web application from the rest of our system environment.
Anyway, as I wrote, I figured out the first part.
How about opening a second Terminal window for entering more commands [that the people at Nintendo may or may not approve of :eek: )
How about opening a second Terminal window for entering more commands [that the people at Nintendo may or may not approve of :eek: )
C'mon, fess up. we all know you're really a nintendo addict. :p
As I said, applescript for terminal.app is seriously buggy. neither the window nor tab elements can be created (you get the 'apple event handler failure' message which means the applescripting isn't implemented for creating those objects). If you don't want to use iTerm, then you'll have to GUI script terminal.app.
tell application "System Events"
tell process "Terminal"
set frontmost to true
keystroke "t" using command down
end tell
end tell
you can then refer to and navigate between tabs regularly, e.g.:
tell application "Terminal"
tell window 1
set selected of tab 1 to true
set selected of tab 2 to true
do script "ls -al" in tab 1
end tell
end tell
t.b.b.
08-14-2010, 03:47 PM
:)
Sweet! Works great. Thank you tw!!!
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.