├── .gitignore ├── LICENSE ├── README.md ├── ScreenShot.png ├── ShadowsocksControler.alfredworkflow └── Source ├── SSR.py ├── icon.png ├── iconb.png └── info.plist /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # PyInstaller 26 | # Usually these files are written by a python script from a template 27 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 28 | *.manifest 29 | *.spec 30 | 31 | # Installer logs 32 | pip-log.txt 33 | pip-delete-this-directory.txt 34 | 35 | # Unit test / coverage reports 36 | htmlcov/ 37 | .tox/ 38 | .coverage 39 | .cache 40 | nosetests.xml 41 | coverage.xml 42 | 43 | # Translations 44 | *.mo 45 | *.pot 46 | 47 | # Django stuff: 48 | *.log 49 | 50 | # Sphinx documentation 51 | docs/_build/ 52 | 53 | # PyBuilder 54 | target/ 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 郭宇翔 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Alfred_ShadowsocksController 2 | 3 | ShadowsocksX-R controller for Alfred 使用 Alfred 控制 ShadowSocks。 4 | 5 | ## 下载 6 | 7 | - 直接下载:[Alfred_ShadowsocksController](https://github.com/yourtion/Alfred_ShadowsocksController/releases/download/0.3/ShadowsocksControler.alfredworkflow) 8 | - Packal: [http://www.packal.org/workflow/shadowsockscontroller](http://www.packal.org/workflow/shadowsockscontroller) 9 | 10 | ## 支持 ShadowSocks 11 | 12 | - ShadowsocksX-R : [ssr_1.3.9 (11/18 fix ApiServer)](https://github.com/yichengchen/ShadowsocksX-R/releases/tag/sst_1.3.9) 13 | 14 | 其他 ShadowSocks 需要等待作者提供 API 支持。 15 | 16 | ## 使用方法 17 | 18 | 1. 下载支持的 ShadowSocks 客户端 19 | 2. 下载 [Alfred_ShadowsocksController](https://github.com/yourtion/Alfred_ShadowsocksController/releases/download/0.3/ShadowsocksControler.alfredworkflow) 20 | 3. 在 Alfred 添加并使用关键字 `ss` 使用功能(支持关键词过滤,如:`mode` `enable` `server` …) 21 | 22 | ![ScreenShot](ScreenShot.png) 23 | 24 | 基本功能已经完成并且可用 25 | 26 | 因为版本更新频繁,现在还是测试开发阶段,欢迎反馈问题,更多版本需要SS客户端支持,届时会进行更新,欢迎 Star 和 Watch 27 | 28 | 29 | -------------------------------------------------------------------------------- /ScreenShot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yourtion/Alfred_ShadowsocksController/eacd0d4740e93d43ec8c6530af3b6c2798c3ed8d/ScreenShot.png -------------------------------------------------------------------------------- /ShadowsocksControler.alfredworkflow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yourtion/Alfred_ShadowsocksController/eacd0d4740e93d43ec8c6530af3b6c2798c3ed8d/ShadowsocksControler.alfredworkflow -------------------------------------------------------------------------------- /Source/SSR.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | import httplib 5 | import json 6 | import urllib 7 | 8 | class Client: 9 | 10 | httpClient = None 11 | SERVER='/servers' 12 | STATUS='/status' 13 | TOGGLE='/toggle' 14 | MODE='/mode' 15 | MODES=['auto','global','manual','bypasschina'] 16 | 17 | def __init__(self): 18 | self.httpClient = httplib.HTTPConnection('localhost', 9528, timeout=30) 19 | 20 | def _get(self, url): 21 | try: 22 | self.httpClient.request('GET', url) 23 | res = self.httpClient.getresponse() 24 | return res if res.status == 200 and res.reason == 'OK' else False 25 | except Exception, e: 26 | return False 27 | 28 | def _post(self, url, parma): 29 | try: 30 | params = urllib.urlencode(parma) 31 | headers = {'Content-type': 'application/x-www-form-urlencoded' 32 | , 'Accept': 'text/plain'} 33 | self.httpClient.request('POST', url, params, headers) 34 | res = self.httpClient.getresponse() 35 | return res if res.status == 200 and res.reason == 'OK' else False 36 | except Exception, e: 37 | return False 38 | 39 | def _parseArgs(self, str): 40 | return str.split(':', 2); 41 | 42 | def _getServers(self): 43 | res = self._get(self.SERVER) 44 | if res: 45 | return json.loads(res.read()) 46 | return [] 47 | 48 | def _getStatus(self): 49 | res = self._get(self.STATUS) 50 | if res: 51 | data = json.loads(res.read()) 52 | return data['enable'] 53 | return False 54 | 55 | def _getMode(self): 56 | res = self._get(self.MODE) 57 | if res: 58 | data = json.loads(res.read()) 59 | return data['mode'] 60 | return 'unknow' 61 | 62 | def _setStatus(self): 63 | res = self._post(self.TOGGLE, {}) 64 | if res: 65 | data = json.loads(res.read()) 66 | return data['Status'] == 1 67 | return False 68 | 69 | def _setServer(self, id): 70 | parma = {'uuid': id} 71 | res = self._post(self.SERVER, parma) 72 | if res: 73 | data = json.loads(res.read()) 74 | return data['status'] == 1 75 | return False 76 | 77 | def _setMode(self, mode): 78 | parma = {'value': mode} 79 | res = self._post(self.MODE, parma) 80 | if res: 81 | data = json.loads(res.read()) 82 | return data['Status'] == 1 83 | return False 84 | 85 | def action(self, query): 86 | args = self._parseArgs(query) 87 | command = args[0] 88 | value = args[1] 89 | if(command == 'enable'): 90 | if(self._setStatus()): 91 | print('Set ShadowSock ' + value + ' Succeed!') 92 | if(command == 'server'): 93 | if(self._setServer(value)): 94 | print('Set Server ' + args[2]) 95 | if(command == 'mode'): 96 | if(self._setMode(value)): 97 | print('Set Server Mode: ' + value + ' Succeed!') 98 | return '' 99 | 100 | 101 | def getList(self): 102 | list = self._getServers() 103 | enable = self._getStatus() 104 | enableStr = 'True' if enable else 'False' 105 | enableOptStr = 'Disable' if enable else 'Enable' 106 | mode = self._getMode() 107 | items = [] 108 | if list and mode: 109 | enableItem = { 110 | 'title':'Enable: ' + enableStr, 111 | 'subtitle': 'Select to '+ enableOptStr, 112 | 'arg': 'enable:'+enableOptStr, 113 | 'icon': {'path': 'icon.png'} 114 | } 115 | if not enable: 116 | enableItem['icon']['path'] = 'iconb.png' 117 | items.append(enableItem) 118 | 119 | for m in self.MODES: 120 | modeItem = { 121 | 'title': 'Mode: '+m.title(), 122 | 'arg': 'mode:'+m, 123 | 'icon': {'path': 'iconb.png'} 124 | } 125 | if m == mode: 126 | modeItem['icon']['path'] = 'icon.png' 127 | modeItem['subtitle'] = 'Current Mode' 128 | else: 129 | modeItem['subtitle'] = 'Switch to ' + m 130 | items.append(modeItem) 131 | 132 | for item in list: 133 | serverItem = { 134 | 'title': 'Server: ' + item['note'], 135 | 'arg': 'server:' +item['id']+':'+item['note'], 136 | } 137 | items.append(serverItem) 138 | else: 139 | notRuning = { 140 | 'title':'ShadowSocks is not runing', 141 | 'subtitle': 'Please start ShadowSocks or update to new version.', 142 | 'icon': {'path': 'iconb.png'} 143 | } 144 | items.append(notRuning) 145 | result = {'items': items} 146 | print(json.dumps(result)) 147 | -------------------------------------------------------------------------------- /Source/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yourtion/Alfred_ShadowsocksController/eacd0d4740e93d43ec8c6530af3b6c2798c3ed8d/Source/icon.png -------------------------------------------------------------------------------- /Source/iconb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yourtion/Alfred_ShadowsocksController/eacd0d4740e93d43ec8c6530af3b6c2798c3ed8d/Source/iconb.png -------------------------------------------------------------------------------- /Source/info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleid 6 | com.yourtion.ssrcontroller 7 | category 8 | Tools 9 | connections 10 | 11 | 03A64B3B-833B-4C81-81C6-8BE345D3BEAC 12 | 13 | 14 | destinationuid 15 | BF6F70C7-C8C7-4D55-B159-38437C1C4807 16 | modifiers 17 | 0 18 | modifiersubtext 19 | 20 | vitoclose 21 | 22 | 23 | 24 | E4C22947-8474-420B-B17F-013B95F81522 25 | 26 | 27 | destinationuid 28 | 03A64B3B-833B-4C81-81C6-8BE345D3BEAC 29 | modifiers 30 | 0 31 | modifiersubtext 32 | 33 | vitoclose 34 | 35 | 36 | 37 | 38 | createdby 39 | Yourtion 40 | description 41 | ShadowsocksX-R controller for Alfred 42 | disabled 43 | 44 | name 45 | ShadowsocksControler 46 | objects 47 | 48 | 49 | config 50 | 51 | concurrently 52 | 53 | escaping 54 | 68 55 | script 56 | import sys 57 | from SSR import Client 58 | 59 | ss = Client() 60 | query = sys.argv[1] 61 | 62 | ss.action(query) 63 | scriptargtype 64 | 1 65 | scriptfile 66 | 67 | type 68 | 3 69 | 70 | type 71 | alfred.workflow.action.script 72 | uid 73 | 03A64B3B-833B-4C81-81C6-8BE345D3BEAC 74 | version 75 | 2 76 | 77 | 78 | config 79 | 80 | lastpathcomponent 81 | 82 | onlyshowifquerypopulated 83 | 84 | removeextension 85 | 86 | text 87 | {query} 88 | title 89 | ShadowSockController 90 | 91 | type 92 | alfred.workflow.output.notification 93 | uid 94 | BF6F70C7-C8C7-4D55-B159-38437C1C4807 95 | version 96 | 1 97 | 98 | 99 | config 100 | 101 | alfredfiltersresults 102 | 103 | argumenttype 104 | 1 105 | escaping 106 | 68 107 | keyword 108 | ss 109 | queuedelaycustom 110 | 3 111 | queuedelayimmediatelyinitially 112 | 113 | queuedelaymode 114 | 0 115 | queuemode 116 | 1 117 | runningsubtext 118 | Loding 119 | script 120 | from SSR import Client 121 | 122 | ss = Client() 123 | 124 | ss.getList() 125 | 126 | scriptargtype 127 | 1 128 | scriptfile 129 | 130 | subtext 131 | 132 | title 133 | {query} 134 | type 135 | 3 136 | withspace 137 | 138 | 139 | type 140 | alfred.workflow.input.scriptfilter 141 | uid 142 | E4C22947-8474-420B-B17F-013B95F81522 143 | version 144 | 2 145 | 146 | 147 | readme 148 | ShadowsocksX-R controller for Alfred 149 | uidata 150 | 151 | 03A64B3B-833B-4C81-81C6-8BE345D3BEAC 152 | 153 | xpos 154 | 350 155 | ypos 156 | 120 157 | 158 | BF6F70C7-C8C7-4D55-B159-38437C1C4807 159 | 160 | xpos 161 | 570 162 | ypos 163 | 120 164 | 165 | E4C22947-8474-420B-B17F-013B95F81522 166 | 167 | xpos 168 | 130 169 | ypos 170 | 120 171 | 172 | 173 | version 174 | 0.3 175 | webaddress 176 | https://github.com/yourtion 177 | 178 | 179 | --------------------------------------------------------------------------------