How can I get Mac OS X's proxy information in a Bash script?

What version of Mac OS X? I'm not positive the tool is included with Mac OS X 10.4 or earlier.

networksetup should be what you're looking for, namely sudo networksetup -getwebproxy NAME_OF_NETWORK_DEVICE (eg. sudo networksetup -getwebproxy Airport)

The output comes out as so:

Enabled: Yes
Server: SERVER_ADDRESS
Port: 123
Authenticated Proxy Enabled: 0 for false, 1 for true

So you will need to convert the output to something usable.

A really crude example using awk a couple times (my awk skills are rather basic) would be:

sudo networksetup -getwebproxy Airport | awk {'print $2'} | awk {'getline l2; getline l3; print "http://"l2":"l3'} | head -n 1

Results in an output http://SERVER_ADDRESS:123


In the answer above, there is a comment from tlrobinson about how it doesn't include the port number.

You can do that by switching out HTTP Proxy Server with HTTP Proxy Port

I have also seen this done like this:

system_profiler SPNetworkDataType | grep "HTTP Proxy Server" | awk '{print $4}' | head -1
system_profiler SPNetworkDataType | grep "HTTP Proxy Port" | awk '{print $4}' | head -1

Additionally this command may help to discover other proxy settings : scutil --proxy