Skip to content

Commit

Permalink
Merge pull request matryer#1466 from glowinthedark/master
Browse files Browse the repository at this point in the history
MacOS proxy switcher (SOCK5 and HTTP)
  • Loading branch information
matryer authored Dec 11, 2020
2 parents 9736810 + 99080e7 commit 75d14e3
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 0 deletions.
121 changes: 121 additions & 0 deletions System/macos-proxy-switcher.1m.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash

# <bitbar.title>MacOS Proxy Switcher</bitbar.title>
# <bitbar.version>v0.1</bitbar.version>
# <bitbar.author>glowinthedark</bitbar.author>
# <bitbar.author.github>glowinthedark</bitbar.author.github>
# <bitbar.desc>Set http and socks5 proxy settings on MacOS.</bitbar.desc>
# <bitbar.image>https://raw.githubusercontent.com/glowinthedark/bitbar-plugins/macos-proxy-switcher/images/mac-proxy-switcher.png.png</bitbar.image>
# <bitbar.dependencies></bitbar.dependencies>
# <bitbar.abouturl>https://github.com/glowinthedark/bitbar-plugins/System/macos-proxy-switcher.1m.sh</bitbar.abouturl>

# CONFIGURATION
INTERFACE=Wi-Fi

SOCKS_PROXY_HOST=localhost
SOCKS_PROXY_PORT=1080

HTTP_PROXY_HOST=localhost
HTTP_PROXY_PORT=8080

PAC_PROXY="file://$HOME/pac_file_proxy.pac"

# END CONFIGURATION

if [[ "$1" = "enable_socks5_proxy" ]]; then
networksetup -setsocksfirewallproxy $INTERFACE $SOCKS_PROXY_HOST $SOCKS_PROXY_PORT
networksetup -setsocksfirewallproxystate $INTERFACE on
exit
fi

if [[ "$1" = "disable_socks5_proxy" ]]; then
networksetup -setsocksfirewallproxystate $INTERFACE off
exit
fi

if [[ "$1" = "enable_http_proxy" ]]; then
networksetup -setwebproxy $INTERFACE $HTTP_PROXY_HOST $HTTP_PROXY_PORT
networksetup -setwebproxystate $INTERFACE on
exit
fi

if [[ "$1" = "disable_http_proxy" ]]; then
networksetup -setwebproxystate $INTERFACE off
exit
fi

if [[ "$1" = "enable_pac_proxy" ]]; then
networksetup -setautoproxyurl $INTERFACE $PAC_PROXY
networksetup -setautoproxystate $INTERFACE on
exit
fi

if [[ "$1" = "disable_pac_proxy" ]]; then
# networksetup -setautoproxyurl $INTERFACE ""
networksetup -setautoproxystate $INTERFACE off
exit
fi


if [[ "$1" = "edit_this_script" ]]; then
# use default editor for .sh extension
# open "$0";
# explicitly use sublimetext3
open -b com.sublimetext.3 "$0";
exit
fi

current_socks5_proxy_status=$(networksetup -getsocksfirewallproxy $INTERFACE | awk 'NR=1{print $2; exit}')
current_http_proxy_status=$(networksetup -getwebproxy $INTERFACE | awk 'NR=1{print $2; exit}')
current_pac_proxy_status=$(networksetup -getautoproxyurl $INTERFACE | grep Enabled | awk 'NR=1{print $2; exit}')

# SOCK5 PROXY
if [[ $current_socks5_proxy_status == "Yes" ]] || [[ $current_http_proxy_status == "Yes" ]] || [[ $current_pac_proxy_status == "Yes" ]] ; then

if [[ $current_socks5_proxy_status == "Yes" ]]; then
echo '🇬🇧'
# networksetup -getsocksfirewallproxy $INTERFACE
fi

if [[ $current_http_proxy_status == "Yes" ]]; then
echo '🌍'
# networksetup -getwebproxy $INTERFACE
fi

if [[ $current_pac_proxy_status == "Yes" ]]; then
echo '📡'
# networksetup -getautoproxyurl $INTERFACE
fi
echo '---'

else
echo "🇪🇸"
echo '---'
fi

echo '---'

if [[ $current_socks5_proxy_status == "Yes" ]]; then
echo "✅ SOCKS PROXY is ON! Click to stop socks5://$SOCKS_PROXY_HOST:$SOCKS_PROXY_PORT | bash='$0' color=indianred param1=disable_socks5_proxy refresh=true terminal=false"
else
echo "❌ SOCKS PROXY is OFF! Click to start socks5://$SOCKS_PROXY_HOST:$SOCKS_PROXY_PORT | bash='$0' param1=enable_socks5_proxy refresh=true terminal=false"
fi

if [[ $current_http_proxy_status == "Yes" ]]; then
echo "✅ HTTP PROXY is ON! Click to stop http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT | bash='$0' color=indianred param1=disable_http_proxy refresh=true terminal=false"
else
echo "❌ HTTP PROXY is OFF! Click to start http://$HTTP_PROXY_HOST:$HTTP_PROXY_PORT | bash='$0' param1=enable_http_proxy refresh=true terminal=false"
fi


if [[ $current_pac_proxy_status == "Yes" ]]; then
echo "✅ PAC PROXY is ON! Click to stop $PAC_PROXY | bash='$0' color=indianred param1=disable_pac_proxy refresh=true terminal=false"
else
echo "❌ PAC PROXY is OFF! Click to start $PAC_PROXY | bash='$0' param1=enable_pac_proxy refresh=true terminal=false"
fi

echo '---'
echo "✏️ Edit this file | bash='$0' param1="edit_this_script" terminal=false"

echo '---'
echo "🔃 Refresh... | refresh=true"
62 changes: 62 additions & 0 deletions System/pmset.5m.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

if [[ "$1" = "pmset_disable_battery_sleep" ]]; then
osascript -e 'display dialog "Disable system sleep while on battery?" buttons {"Cancel", "DISABLE NOW! (System will NOT sleep!)"}
do shell script "/usr/bin/pmset -a disablesleep 1" with administrator privileges'
exit
fi

if [[ "$1" = "pmset_restore_battery_sleep" ]]; then
osascript -e 'display dialog "Restore sleep mode back to normal?" buttons {"Cancel", "RESTORE NORMAL SLEEP"}
do shell script "/usr/bin/pmset -a disablesleep 0" with administrator privileges'
exit
fi

if [[ "$1" = "stop_caffeinate" ]]; then
pkill caffeinate
exit
fi

if [[ "$1" = "start_caffeinate" ]]; then
/usr/bin/caffeinate -sdi &
exit
fi

if [[ "$1" = "edit_this_script" ]]; then
open -b com.sublimetext.3 "$0"
exit
fi

sleep_disabled=$(pmset -g | grep SleepDisabled | awk '{print $2}')

is_caffeinate_running=$(pgrep caffeinate)

if [[ $sleep_disabled == "0" ]]; then
if [[ $is_caffeinate_running -eq 0 ]] ; then # "1" = no processes found
echo "🔵"
status="💤 Sleeping normally"
else
echo "☕️"
status="caffeinating... ☕️"
fi
cmd="🔋 pmset: Disable sleep on battery | bash='$0' param1=pmset_disable_battery_sleep terminal=false refresh=true"
else
echo "‼️"
status="‼️ Preventing sleep on battery"
cmd="🔥 pmset: RESTORE sleep on battery | bash='$0' color=indianred param1=pmset_restore_battery_sleep terminal=false refresh=true"
fi

echo '---'
echo "$status"
echo '---'
echo "$cmd"

if [[ $is_caffeinate_running -eq 0 ]] ; then
echo "☕️ caffeinate | bash='$0' param1=start_caffeinate refresh=true terminal=false"
else
echo "❌ [caffeinate already running] KILL NOW | bash='$0' color=indianred param1=stop_caffeinate refresh=true terminal=false"
fi
echo '---'
echo "✏️ Edit this file | bash='$0' param1="edit_this_script" terminal=false"
echo '---'
echo "🔃 Refresh... | refresh=true"

0 comments on commit 75d14e3

Please sign in to comment.