PDA

View Full Version : Apple Script/ Terminal


steveo
08-21-2002, 06:33 PM
I'm new to applescript. I can't figure out how to get applescript to talk to the terminal and actually "enter" commands. I want to make a custom script for myself and a few friends. Our apples need to ping our schools proxy server every 5 mins to stay active, or else we have to log in to browse the web if we're idle for more than 5 mins.

I want the apple script to
tell terminal to activate

then enter the commands ping -i 300 "proxy address"
then background it and disown it and quit terminal.

I can do this fine by myself, but my friends don't know/understand terminal, unix, etc. I'd like to make a script, but I can't figure out how. Is this possible to have apple script tell terminal to enter certain commands? Please help.

Thank you for your help

Steve

rusto
08-21-2002, 08:47 PM
You'll want to investigate the following AppleScript command introduced for OS X:

do shell script "some command line gobble-dee-goop"

No need to actually call the terminal directly, just send the commands directly to the shell.

Note: every "do shell script" call is like opening a new Terminal window, so you will want to try to get all your code on one line...something along these lines:


do shell script "ping - i 300 proxyAddress"


If you need admin priviledges it would look like this:


do shell script "ping -i 300 proxyAddress" with administrator privileges

and when you run it, the script will ask for your admin password.

steveo
08-22-2002, 06:46 PM
Thanks for the reply. I tried both of them, and they work fine. I need to go out and get a book on this.

How do I keep telling the terminal to enter multiple commands? With multiple do shell script calls? I want one shell just to automate a task for me that I do frequently.

Also, ZSH says ping isn't recognized? Interesting. Is there a way to switch the default that do shell runs with..like to tcsh?

Thanks

mervTormel
08-22-2002, 07:20 PM
with all scripts, you should use full pathnames to the command...

/sbin/ping args

i think what you want is a looping background script with a ping just under a wait interval of 300 seconds in it...

try something like:

do shell script
"while true; do /sbin/ping -i 290 yahoo.com | /usr/bin/tee ~/keepalive; done"

but that needs some cleaning up, like how to tell it to stop nicely.

steveo
08-23-2002, 08:55 AM
Thanks guys. It means a lot that you took your time out to help me for a few.

Any books/websites you guys can personally recommend to learn more about Unix/applescript?

Thanks guys