Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 18, 2012, 11:34 PM   #1
tatchley
macrumors newbie
 
Join Date: Oct 2012
Script to change proxy settings

Hello all,

At this point, I am frustrated by my lack of programing knowledge. With one click, I would like to be able to start/close a specific application and automatically enable/disable the system's SOCKS Proxy. I know it can be done, and I have googled with various results, but nothing that would suit my needs. So that is why I am here: to ask if there are any of your who would be willing to, out of the goodness of your hearts, write me a script that could do this. I have nothing to offer you in return. I'm sure for someone with even notice experience, this would be a simple undertaking, but, alas, I do not even have that. Like I said, I would want the script to launch a certain application (I can write it in if I know the syntax) and to switch the SOCKS proxy to on. Also, I would like the script to close the application and turn off the proxy when I click it again. Would any of you help me? Thanks for reading this far.
tatchley is offline   0 Reply With Quote
Old Oct 19, 2012, 03:16 AM   #2
blaster_boy
macrumors regular
 
Join Date: Jan 2004
Location: Belgium
You need to supply a few more details :
- script for mac ?
- for windows ?
- what application exactly do you need to open and close ?

More details helps !
__________________
Every day is another day to learn something useful.
blaster_boy is offline   0 Reply With Quote
Old Oct 19, 2012, 09:42 AM   #3
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Something to get you started :

Code:
(*
The TextEdit application is used as a general example
 Replace "com.apple.TextEdit" with the bundle identifier from the actual application you would like to start/stop
 The example is the bundle identifier from the TextEdit application
*)
tell application "System Events"
	set isRunning to (count of (every process whose bundle identifier is "com.apple.TextEdit")) > 0
end tell

-- Check if application is running
if isRunning then
	-- Close the application
	tell application "TextEdit" to quit
	(*
	Disable the system's SOCKS Proxy
	Take a look at the networksetup command.
	Open Terminal application an type networksetup for more information
	Don't know if this is the setting you want :
	networksetup -setsocksfirewallproxy Ethernet 127.0.0.1 1080 off
	-setsocksfirewallproxy – tells networksetup to turn the proxy on, with the following settings
	 Ethernet – the identifier of the network service to change the settings for (e.g. AirPort, Ethernet). Use networksetup -listallnetworkservices to see all valid values.
	127.0.0.1 – the address of the SOCKS proxy.
	1080 – the port of the SOCKS proxy.
	 off – this is for authentication
	 You can just as simply disable the proxy.
	 networksetup -setsocksfirewallproxystate Ethernet off
	 Again, substitute Ethernet for your network service name if necessary (probably either AirPort or Ethernet).
	 It is also possible, once the settings are remembered by Mac OS X, to just use:
	 networksetup -setsocksfirewallproxystate Ethernet on
*)
	do shell script "networksetup -setsocksfirewallproxystate Ethernet off" --with administrator privileges user name password
else
	-- Enable the system's SOCKS Proxy
	do shell script "networksetup -setsocksfirewallproxystate Ethernet on" --with administrator privileges user name password
	-- Activate the application
	tell application "TextEdit" to activate
end if
Or with a simple dialog :

Code:
display dialog "Start/stop application and enable/disable the system's SOCKS Proxy." buttons {"Cancel", "Stop", "Start"} default button 3
if the button returned of the result is "Start" then
	do shell script "networksetup -setsocksfirewallproxystate Ethernet on" --with administrator privileges user name password
	tell application "TextEdit" to activate
else
	tell application "TextEdit" to quit
	do shell script "networksetup -setsocksfirewallproxystate Ethernet off" --with administrator privileges user name password
end if

To get the bundle identifier for your application :

Code:
-- Replace TextEdit with the right application
get bundle identifier of (info for (path to application "TextEdit"))
Info : https://developer.apple.com/library/...rksetup.8.html
__________________
Space Corps Directive 34124

Last edited by kryten2; Oct 19, 2012 at 01:04 PM.
kryten2 is offline   0 Reply With Quote
Old Oct 19, 2012, 04:26 PM   #4
tatchley
Thread Starter
macrumors newbie
 
Join Date: Oct 2012
Wow...

That was an awesome reply kryton2. Thanks a bundle. The shorter script works great. I have two more questions though: 1. Could you tweak the script to automatically detect whether the application is open or not and act accordingly? I would like minimize on the number of clicks. Less clicks = more . 2. Could you tweak the script to temporarily assume administrative privileges when running? I have a rather long password, and it would be painful to have to type it out each time. As I said before, less clicks = more .

If you cannot comply, do not worry about it. How can I complain about a free product?
tatchley is offline   0 Reply With Quote
Old Oct 19, 2012, 05:38 PM   #5
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Regarding your questions.

1) Try the first script
2) Remove the dashes from the do shell script lines eg :

Code:
do shell script "networksetup -setsocksfirewallproxystate Ethernet off" with administrator privileges user name "yourusername" password "yourpassword"
__________________
Space Corps Directive 34124
kryten2 is offline   0 Reply With Quote
Old Oct 19, 2012, 09:49 PM   #6
tatchley
Thread Starter
macrumors newbie
 
Join Date: Oct 2012
Splendid. Thank you for your kindness. One last thing: How can I set the permissions of the app so that it requires administrative credentials to view? I would not like just anyone to be able to view the script, and more importantly my login information.
tatchley is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Settings to change under Menu Settings?? alexxk Digital Photography 3 Oct 10, 2013 11:09 AM
Proxy Settings RagingGoat OS X 0 Jan 18, 2013 10:25 AM
Can't store proxy settings Chancer OS X 10.8 Mountain Lion 4 Dec 14, 2012 09:02 AM
Global Proxy Settings gwelmarten iOS 6 1 Jun 25, 2012 10:44 AM
under wifi settings what is HTTP PROXY then 3 options aliensarecool iPhone 1 Jun 10, 2012 11:14 AM

Forum Jump

All times are GMT -5. The time now is 08:13 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC