Jump to content

Alfred Doesn't use Proxy?


Recommended Posts

Terminal.app/iTerm.app don't set http(s)_proxy for you, regardless of the settings in System Preferences > Network.

 

Proxy env vars have to be set manually or in your dotfiles.

 

Do scripts run in Terminal work with the auto discovery options? Or do these always need to be manually set... I'm just trying to see what Alfred may have to do for this, and how possible it is.

Link to comment

Fundamentally, Terminal.app (and iTerm.app) do not export any proxy settings in System Preferences to shells.

 

iTerm.app itself does use the system proxy when checking for updates because it's a Cocoa app, but neither of the apps do (or can be configured to) export the proxy settings to the shells running within them.

 

Shells apparently run at the lower UNIX system level, while the proxy servers configured in System Preferences belong to the Objective-C runtime.

 

To use a proxy from anything that's standard UNIX in the shell, you have to set http_proxy/https_proxy manually. Any settings in System Preferences are ignored.

 

Auto Proxy Discovery and Automatic Proxy Configuration are two different, but related, things. The former is a protocol usually used to find the latter, which is a JavaScript file that when executed tells the client whether to use proxy server XXX or connect directly.

 

I have my proxy.pac set up to tell applications to either use the proxy server or connect directly based on the user agent. I want some apps to use my ad-blocking proxy and others to be subject to Little Snitch. Alfred is always given the proxy.

 

I've run a few tests, changing my proxy.pac file to always specify the proxy server, and never direct, but still using Automatic Proxy Configuration.

 

In that case, Alfred uses the proxy (to check for updates etc.), as does targumanu's IMDb workflow, which is written in Objective-C, however the http_proxy and https_proxy environmental variables remain empty in Alfred's calling environment, so Python/Ruby/cURL do not use the proxy server.

 

To be clear, it's unreasonable to expect that my proxy.pac would fully work with workflows (i.e. they run proxy.pac and it sends DIRECT or PROXY XXX back based on the workflow's user agent), but Alfred is being told to use the proxy and isn't propagating that setting.

Edited by deanishe
Link to comment

Alfred isn't being told to use the proxy, it's more complicated than that. In Obj C, the auto proxy configuration resolution when using network code is deep rooted within the network calls themselves without Alfred doing anything, this is why things like auto update automatically work. They are also point in time resolutions, i.e. "trying to do a network call -> look up proxy -> do network call", unlike running workflows where the scripts are being run maybe many times per second and Alfred doesn't even know if they are doing any network interactions.

 

For workflows, I'm specifically having to obtain the OS X static proxy configuration information from the SC framework and manually set the http_proxy and https_proxy configuration into the task.

 

While I can get the URL to the pac file, I see no mechanism to resolve this proxy for subsequently manually setting the http_proxy or https_proxy.

Link to comment

Is there anyway that you could source/load the dotfiles with Alfred before executing any workflow?

 

This wouldn't be a good idea anyway as it would make the configuration for a [shared] workflow dependant on the shell configuration of the workflow developer. You can manually source your own dot files though.

Link to comment

Alfred isn't being told to use the proxy, it's more complicated than that. In Obj C, the auto proxy configuration resolution when using network code is deep rooted within the network calls themselves without Alfred doing anything, this is why things like auto update automatically work.

 

I only meant that my proxy.pac was definitely sending PROXY XXX, not DIRECT, when it sees Alfred's user-agent, i.e. I wasn't sending the wrong value.

 

For workflows, I'm specifically having to obtain the OS X static proxy configuration information from the SC framework and manually set the http_proxy and https_proxy configuration into the task.

While I can get the URL to the pac file, I see no mechanism to resolve this proxy for subsequently manually setting the http_proxy or https_proxy.

I hadn't thought that through properly. I looked at the proxy.pac format again, and it just doesn't work that way. The client is supposed to call the FindProxyForURL(url, host) defined in proxy.pac for every URL (hence the point-in-time resolution), which Alfred can't do for its workflows.

Static values for http_proxy and https_proxy are the shell standard for proxy servers, and Alfred can't be expected to provide more that than.

Any script that works with a proxy server from a shell should now also work in Alfred, but with the sweet bonus that Alfred also automatically adjusts the proxy server based on OS X's Network Location, which you can't do properly in a shell.

 

Thanks very much for adding this feature to Alfred. It isn't really possible to do from within a workflow, and that made a lot of them useless for some users pre 2.4.

 

I guess Auto Proxy Configuration will have to remain the exclusive preserve of Objective-C workflows…

Edited by deanishe
Link to comment
  • 3 years later...

Recently came across this problem.

 

google suggestions, wunderlist, Spotify mini player.... don't work when I'm in the office and I'm on auto proxy config (with the old Mac I used to switch manually each day which was a real pain).

 

Did I misunderstand something? Or is this an on-going and unsolvable problem?

 

Thanks

 

 

 

Link to comment
On 6/5/2018 at 3:02 PM, milfred said:

Did I misunderstand something? Or is this an on-going and unsolvable problem?

 

Getting Automatic Proxy Configuration to work with (non-native) workflows is essentially an unsolvable problem. I explained why in the post immediately above yours.

 

On 6/5/2018 at 3:02 PM, milfred said:

I used to switch manually each day which was a real pain

 

Then you were doing it wrong… ;) Don't edit the proxy settings, create a new network location (e.g. "Work") and just switch locations. You can also use applications like ControlPlane or Hammerspoon to automatically change network locations for you. Personally, I use ControlPlane for this.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...