Bandwidth Throttle Script

I’m sure this is easy for most of you but…

When I manually enter these three lines into Terminal, I get the desired result. However, I’d like to write an AppleScript (or Automator) that will automate this. I have tried numerous approaches, both within AppleScript and Automator, and have failed (I’m new to scripting). Will someone please help me?

Here are the three lines I’m trying to convert into some kind of executable AppleScript or Automator app:

sudo /usr/local/sbin/throttled -s 96256 -r 00070 -d 17778 -p 1 -d 17777 -p 2
sudo /sbin/ipfw add 00070 divert 17778 tcp from any 5500-5501 to any out xmit en0
sudo /sbin/ipfw add 00070 divert 17778 tcp from any to any 5500-5501 out xmit en0

Thanks!

Try doing one of these in Script Editor…

do shell script "sudo /usr/local/sbin/throttled -s 96256 -r 00070 -d 17778 -p 1 -d 17777 -p 2; sudo /sbin/ipfw add 00070 divert 17778 tcp from any 5500-5501 to any out xmit en0; sudo /sbin/ipfw add 00070 divert 17778 tcp from any to any 5500-5501 out xmit en0

probably more likely to work…

do shell script "sudo /usr/local/sbin/throttled -s 96256 -r 00070 -d 17778 -p 1 -d 17777 -p 2"
do shell script "sudo /sbin/ipfw add 00070 divert 17778 tcp from any 5500-5501 to any out xmit en0"
do shell script "sudo /sbin/ipfw add 00070 divert 17778 tcp from any to any 5500-5501 out xmit en0"

if you get a response from terminal that is important you may want this code:

set result1 to do shell script "sudo /usr/local/sbin/throttled -s 96256 -r 00070 -d 17778 -p 1 -d 17777 -p 2"
set result2 to do shell script "sudo /sbin/ipfw add 00070 divert 17778 tcp from any 5500-5501 to any out xmit en0"
set result3 to do shell script "sudo /sbin/ipfw add 00070 divert 17778 tcp from any to any 5500-5501 out xmit en0"
display alert result1 & "-" & result2 & "-" & result3 

hope that helps

Thank you! I revised it a bit to the following (added authentication), and it works.

do shell script "sudo /usr/local/sbin/throttled -s 94400 -r 00070 -d 17778 -p 1 -d 17777 -p 2; sudo /sbin/ipfw add 00070 divert 17778 tcp from any 5500-5501 to any out xmit en0; sudo /sbin/ipfw add 00070 divert 17778 tcp from any to any 5500-5501 out xmit en0" password my_password with administrator privileges

There is no need for sudo when using do shell script . with administrator privileges. See Technical Note TN2065: do shell script in AppleScript section titled Q: How do I get administrator privileges for a command? for the details (though as it says, if you need to support systems prior to 10.4 you will need to make a change).