yxjxx
5/6/2017 - 1:37 PM

bitbar plugin: shadowsocksX status

bitbar plugin: shadowsocksX status

#!/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()