Greetings all,
I am desperately trying to figure this out - I am not good at programming, but I am trying to do something that I can only assume is very basic.
I am trying to send certain text to a terminal window. All I want to do is send the same thing, wait 15 seconds, and send it again then repeat. Ideally, I would be able to control two or three terminal windows sending the same thing at different intervals.
I am somewhat reliving my youth when I played certain MUD games via telnet and they are really ideal for PC and alas I have moved on to MAC in my later years. I have been having difficulty understanding applescript to do this where I used to know how for PC based scripts.
Any help is greatly appreciated, and I am sorry if I offended anyone because I am asking for someone to make a script. I just figured the function is so basic it would not be a problem/difficult. Thanks again.
Fitzhume
I don’t know anything about MUDs, but it is possible to execute a shell script directly from AppleScript without using the terminal, and it’s possible to read a wide variety of internet communications with a UNIX program called cURL. Mightn’t that be a better way to go?
Even better, at Freshmeat.net, there’s a list of free software for playing MUDs.
I guess to be more specific I was hoping there would be a basic AppleScript that would send certain text to an open shell in terminal, wait 15 seconds, then send it again.
I am using it connect to a BBS to play an online text game. Back in the day when everything was DOS oriented, it was easy to write these scripts. I guess I can’t figure out how to use AppleScript for this basic function since it seems to be primarily used to control applications. The only existing scripts for these are all on the PC based telnet clients.
Is it possible to get an AppleScript to send text to an open shell? Any help is greatly appreciated, thanks!
Fitzhume
A simple example might look like this:
tell application "Terminal"
do script "echo 'I like to play in the MUD.'" in window 1
end tell
However, that won’t work for sending text to an interactive process. You’ll probably have to resort to sending keystrokes with System Events:
activate application "Terminal"
tell application "System Events"
keystroke "echo 'I like to play in the MUD.'" & return
end tell
(If you want to compare the two scripts, run nano
(a text editor) in Terminal and then try the scripts.)
I think that the second part might be what I was looking for. I am going to try it out a bit and see if I can get it to work. My only question would be if I can add delays after each keystroke and either repeat that a bunch, or is there a command to put it on repeat? Thanks.
Fitzhume
FYI -
Just tried the “System Events” script and it works perfectly. I guess back to my previous post, is there a way I can loop it instead of ending the tell? Also, if I opened two terminal windows, could I send different tasks to each window? If its kinda complicated, I can live without the last part.
Fitzhume
That would be more complicated…
What I would do is save this as a “stay open” application, so that you can more easily quit the script when you’re done with it.
on idle
activate application "Terminal"
tell application "System Events"
keystroke "north" & return
delay 0.5 -- time in seconds; remove or adjust as needed
keystroke "look"
end tell
return 300 -- delay time in seconds
end idle
Thanks again for all your help Bruce.
Fitzhume