Skip to content

Instantly share code, notes, and snippets.

@yxjxx
Last active May 6, 2017 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yxjxx/aa09b5c10ae530987b66da328f156bb7 to your computer and use it in GitHub Desktop.
Save yxjxx/aa09b5c10ae530987b66da328f156bb7 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment