Last active
May 6, 2017 13:38
-
-
Save yxjxx/aa09b5c10ae530987b66da328f156bb7 to your computer and use it in GitHub Desktop.
bitbar plugin: shadowsocksX status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Users/yxj/env/bin/python | |
# -*- coding: utf-8 -*- | |
# @Author: yxjxx | |
# @Date: 2016-01-09 13:28:49 | |
# @Last Modified by: yxjxx | |
# @Last Modified time: 2016-01-09 19:04:17 | |
from biplist import * | |
from os.path import expanduser | |
import json | |
def main(): | |
try: | |
filepath = expanduser( | |
"~/Library/Preferences/clowwindy.ShadowsocksX.plist") | |
plist = readPlist(filepath) | |
isRuning = plist['ShadowsocksIsRunning'] # True or False | |
if not isRuning: | |
print "Off" | |
return | |
config_dict = json.loads(plist['config']) # plist['config'] is str | |
current_num = config_dict['current'] # config_dict['current'] is int | |
current_server = config_dict['profiles'][current_num]['remarks'] | |
mode = plist['ShadowsocksMode'] # auto or global | |
if isRuning and mode == "global": | |
print "Global | color=red size=14 font=Tahoma-Bold" | |
elif isRuning and mode == "auto": | |
print current_server | |
except (InvalidPlistException, NotBinaryPlistException), e: | |
print "Not a plist:", e | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment