Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Toggle web proxy settings via AppleScript Internet
I often have to switch between a proxy server and direct connexion to the internet - whether I'm doing stuff for work or me. I wrote a small AppleScript to automate the process (using Apple's System Events extension).

Hope this helps (read the rest of the hint for the script)...


set proxyServer to "proxy.example.com"
set proxyPort to "3128"

tell application "System Preferences"
 activate
end tell
tell application "System Events"
 get properties
 tell process "System Preferences"
  click menu item "Network" of menu "View" of menu bar 1
  delay 2
  tell window "Network"
   tell group 1
    tell tab group 1
     click radio button "Proxies"
     tell group 1
      if value of static text 1 of window "Network" of process 
      "System Preferences" of application "System Events" is 
      "Click the lock to make changes." then click button 4 of 
      window "Network" of process "System Preferences" of 
      application "System Events"
                                              
      click check box "Web Proxy (HTTP)"
      if value of check box "Web Proxy (HTTP)" is 1 then
       set outStr to "Turned Proxy ON " & return & 
       "(set to '" & proxyServer & ":" & proxyPort & "')"
      else
       set outStr to "Turned Proxy OFF"
      end if
                                               
      set value of text field 10 to proxyServer
      set value of text field 11 to proxyPort
     end tell
    end tell
   end tell
   click button "Apply Now"
  end tell
 end tell
end tell

ignoring application responses
 tell application "System Preferences" to quit
end ignoring

display dialog outStr buttons {"Ok"} giving up after 2
    •    
  • Currently 2.71 / 5
  You rated: 2 / 5 (7 votes cast)
 
[33,646 views]  

Toggle web proxy settings via AppleScript | 19 comments | Create New Account
Click here to return to the 'Toggle web proxy settings via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Toggle web proxy settings via AppleScript
Authored by: RHG on Oct 20, '03 12:20:49PM

I've never touched applescript before, but this sounds useful enough that I'd like to try it. How do I make this into a button I click on somewhere?



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: RickoKid on Oct 20, '03 03:46:22PM

To make an AppleScript clickable ... just open it up in Applescript Editor and save it as an Application (it's an option of the "Format" drop down box in the Save Dialog)

---


RickoKid



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: BobHarris on Oct 20, '03 12:30:43PM

I get the same effect, by having 2 different network locations and use the Blue Apple Menu to change locations. One location has a proxy and the other does not.



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: afranz on Oct 20, '03 01:02:07PM

Using the 'location' menu does the trick for me too, but I still need to tell Mozilla to use a proxy or has someone a script for that as well, I haven't looked into Applescript that much yet. Thanks



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: Anonymous on Oct 20, '03 02:08:44PM

You know that domains can be excluded for going through the proxy? It's in the proxy panel, just enter your development sites, like i do.



[ Reply to This | # ]
Privoxy
Authored by: luhmann on Oct 20, '03 04:07:56PM

Perhaps this should be its own hint, but you can force domains to use different proxies by using the freeware ad-filtering software Privoxy. If you add a "forward" command to the config file, you can direct all traffic for specific domains to whatever proxy you like!



[ Reply to This | # ]
Privoxy, and excluding certain sites from proxying
Authored by: ZZamboni on Oct 20, '03 06:12:58PM

I recently installed Privoxy on my Powerbook at home (I've been using it for a while in my Linux machine at work - it's a very nice piece of software), but discovered that software update fails when using it. I tried adding apple.com, .apple.com, and swscan.apple.com to the "excluded" list in the Network preferences panel, but SU still insisted on using the proxy. Does anyone know how to achieve this?



[ Reply to This | # ]
Privoxy, and excluding certain sites from proxying
Authored by: Bipp on Oct 20, '03 11:01:57PM

add domains to be excluded or filtered in privoxy itself



[ Reply to This | # ]
Privoxy, and excluding certain sites from proxying
Authored by: david-bo on Oct 21, '03 04:24:43PM

I have used privoxy for years on Mac with no problem what so ever with SU. You must have some other problem.

HTH

---
http://www.google.com/search?as_q=%22Authored+by%3A+david-bo%22&num=10&hl=en&ie=ISO-8859-1&btnG=



[ Reply to This | # ]
Privoxy, and excluding certain sites from proxying
Authored by: grogglefroth on Oct 25, '03 02:40:13PM

I exclude the following; and software update works for me.
mac.com
apple.com
swscan.apple.com

Also, for techtracker.com's application, I exclude:
techtracker.com
versiontracker.com
client.versiontracker.com



[ Reply to This | # ]
s/w update
Authored by: LouieNet on Nov 02, '03 03:27:15AM
The fix is to turn off the demoronizer filter. The Privoxy bug report section has the description of the fix: http://sourceforge.net/tracker/index.php?func=detail&aid=754056&group_id=11118&atid=111118 The latest version might even have that filter turned off by default.

---
G4 cube, 1152M RAM, OS X Server 10.2.6

[ Reply to This | # ]

Privoxy, and excluding certain sites from proxying
Authored by: david-bo on Nov 07, '10 03:18:12AM

Look here

https://sourceforge.net/tracker/index.php?func=detail&aid=2933856&group_id=11118&atid=460288

---
link



[ Reply to This | # ]
Great script--please extend it!
Authored by: pzingg on Oct 22, '03 11:36:14PM

I love this script.

How about enhancing the script to set the "bypass these hosts" box? I currently have to manually type in 5 host names on every machine I set up.



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: LeadDog on Oct 25, '03 02:27:22PM

I would like to use this AppleScript but when I paste it into Script Editor I get the following error message. "Expected end of line but found class name." Script Editor highlights menu item in this line.

click menu item "Network" of menu "View" of menu bar 1

Any ideas?



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: RHG on Oct 28, '03 08:40:55AM

Yeah, me too.



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: RickoKid on Nov 23, '03 06:38:41PM
I got asked to update my script for Panther - here it is. This script chooses the right pane in System Preferences by using the System Preferences scripting interface rather tha GUI interface - bit faster! Here it is:
set proxyServer to "proxy.example.com"
set proxyPort to "3128"

tell application "System Preferences"
	activate
	set current pane to pane "com.apple.preference.network"
end tell
tell application "System Events"
	get properties
	tell process "System Preferences"
		tell window "Network"
			click pop up button 2
			click menu item "Built-in Ethernet" of menu "OtherViews" of pop up button 2
			tell group 1
				tell tab group 1
					delay 1
					click radio button "Proxies"
					try
						click button "Click the lock to make changes." of window "Network" of process 
							"System Preferences" of application "System Events"
					end try
					tell group 1
						tell table 1 of scroll area 1
							set selected of row 2 to true
							click checkbox of row 1
							if value of (checkbox 1 of row 2) is 1 then
								set outStr to "Turned Web Proxy ON " & return 
									& "(set to '" & proxyServer & ":" & proxyPort & "')"
							else
								set outStr to "Turned Web Proxy OFF"
							end if
						end tell
						tell group 1
							set value of text field 2 to proxyServer
							set value of text field 1 to proxyPort
						end tell
					end tell
				end tell
			end tell
			click button "Apply Now"
		end tell
	end tell
end tell

ignoring application responses
	tell application "System Preferences" to quit
	display dialog outStr buttons {"Ok"} giving up after 2
end ignoring

---


RickoKid

[ Reply to This | # ]

Toggle web proxy settings via AppleScript
Authored by: efs on Mar 29, '04 10:31:01PM

I'm using 10.3.3 and this script bombed on me... right around the
[click menu item "Built-in Ethernet" of menu "OtherViews" of pop up button 2].

Before I play around with it -- considering I'm not too good at scripting yet -- has there been a menu change since this script was working for an earlier version of Panther?



[ Reply to This | # ]
Toggle web proxy settings via AppleScript (my error!)
Authored by: efs on Mar 30, '04 06:04:21PM

Apologies... misread RickoKid's posting about GUI scripting and thought it was no longer required... then looked at the code and saw I misread his comment, which only applies to activating network preferences.

It works fine. Blame the user (me). Thanks for the script!



[ Reply to This | # ]
Toggle web proxy settings via AppleScript
Authored by: s3pt1k on Aug 31, '05 01:52:42PM

Anyone have this script updated for Tiger?



[ Reply to This | # ]