set this_URL to "http://www.google.com/"
set URLWithString to call method "URLWithString:" of class "NSURL" with parameter this_URL
set sharedNetworkSettings to call method "sharedNetworkSettings" of class "NSNetworkSettings"
set proxyPropertiesForURL to call method "proxyPropertiesForURL:" of sharedNetworkSettings with parameter URLWithString
set {HTTP_proxy, HTTP_proxy_port} to {"", 80}
set {HTTPS_proxy, HTTPS_proxy_port} to {"", 80}
tell |kCFStreamPropertyHTTPProxy| of proxyPropertiesForURL
set HTTP_proxy_enabled to ((its |HTTPEnable|) = 1)
if HTTP_proxy_enabled then
set HTTP_proxy to its |HTTPProxy|
set HTTP_proxy_port to its (|HTTPPort|) as integer
end if
set HTTPS_proxy_enabled to ((its |HTTPSEnable|) = 1)
if HTTPS_proxy_enabled then
set HTTPS_proxy to its |HTTPSProxy|
set HTTPS_proxy_port to its (|HTTPSPort|) as integer
end if
end tell
return {HTTP_proxy_enabled:HTTP_proxy_enabled, HTTP_proxy:HTTP_proxy, HTTP_proxy_port:HTTP_proxy_port, HTTPS_proxy_enabled:HTTPS_proxy_enabled, HTTPS_proxy:HTTPS_proxy, HTTPS_proxy_port:HTTPS_proxy_port}
Can any one else confirm that this works for them? I need compatibility back to 10.2. Is this safe to use? Even if this does return the proper proxy info on 10.2+, is there some better way to get the HTTP & HTTPS proxy info?
Thanks for the confirmation and hint (as always, you’re very helpful). Anyone have confirmation on earlier systems? As to that plist file, it is hard to parse (at least on my system) because the string that is listed for the currentSet value is not actually found in any of the known sets it tracks. The name (encoded) is a few characters different from a set contained in the NetworkSettings default in the same file. Since I couldn’t match it from the name, I didn’t know which set’s proxy info to use. Incidentally, for people who want an easy way to parse a plist file in an AS Studio app, try the following (it should return the contents of a plist file as a record or a list of records):
set the_record to my read_plist(POSIX path of (choose file with prompt "Choose a plist file:"))
log the_record
on read_plist(the_path)
try
set a to call method "arrayWithContentsOfFile:" of class "NSArray" with parameter the_path
return a
on error
try
set d to call method "dictionaryWithContentsOfFile:" of class "NSDictionary" with parameter the_path
return d
on error
return false
end try
end try
end read_plist