├── icon.png ├── viscosity.png ├── state.ascr ├── connections.ascr ├── README.md └── info.plist /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewschleifer/viscosity-alfredworkflow/HEAD/icon.png -------------------------------------------------------------------------------- /viscosity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewschleifer/viscosity-alfredworkflow/HEAD/viscosity.png -------------------------------------------------------------------------------- /state.ascr: -------------------------------------------------------------------------------- 1 | on run argv 2 | tell application "Viscosity" to return state of (connections where name is item 1 of argv) 3 | end run 4 | -------------------------------------------------------------------------------- /connections.ascr: -------------------------------------------------------------------------------- 1 | set output to "" 2 | tell application "Viscosity" to set ls to name of every connection 3 | repeat with n in ls 4 | set output to output & n & return 5 | end repeat 6 | return output 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | Viscosity Workflow for Alfred 3 | ============================= 4 | 5 | This is a workflow for [Alfred](http://www.alfredapp.com/) that 6 | works with [Viscosity](http://www.sparklabs.com/viscosity/) to control 7 | OpenVPN connections. 8 | 9 | The configured keyword is `vpn`. That will show all of your configured 10 | networks initially, and autocompletes (case-insensitively) on the 11 | argument if one is provided. 12 | 13 | The subtitle tells you if actioning the selection will connect or 14 | disconnect from that network. 15 | 16 | There are Connect All/Disconnect All operations that will act on 17 | all VPN endpoints you've defined. 18 | 19 | ![Screenshot](viscosity.png) 20 | 21 | 22 | 23 | # how to install 24 | ` git clone https://github.com/andrewschleifer/viscosity-alfredworkflow.git $HOME/Library/Application\ Support/Alfred/Alfred.alfredpreferences/workflows/viscosity 25 | ` 26 | 27 | -------------------------------------------------------------------------------- /info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleid 6 | 7 | connections 8 | 9 | 14D5E084-1B24-4FEC-B287-ADE8530320F2 10 | 11 | 12 | destinationuid 13 | 58FEBA95-060B-4B7C-9516-2B60011E5A3C 14 | modifiers 15 | 0 16 | modifiersubtext 17 | 18 | 19 | 20 | 21 | createdby 22 | Various Artists 23 | description 24 | Control OpenVPN connections 25 | disabled 26 | 27 | name 28 | Viscosity 29 | objects 30 | 31 | 32 | config 33 | 34 | argumenttype 35 | 1 36 | escaping 37 | 63 38 | keyword 39 | vpn 40 | script 41 | STAMP=$(date +%s) 42 | FILTER="{query}" 43 | if [ -z "$FILTER" ]; then FILTER=.;fi 44 | echo '<?xml version="1.0"?><items>' 45 | 46 | osascript -sh connections.ascr | tr "\r" "\n" | grep -i $FILTER | while read LINE; do 47 | echo "<item uid=\"${STAMP}\" arg=\"${LINE}\"><title>${LINE}</title>" 48 | if [[ $(osascript -sh state.ascr "${LINE}" | tr "\r" "\n" | grep -i .) == "Connected" ]]; then 49 | echo "<subtitle>Disconnect from this network</subtitle>" 50 | else 51 | echo "<subtitle>Connect to this network</subtitle>" 52 | fi 53 | echo "<icon>icon.png</icon><valid>yes</valid></item>" 54 | done 55 | 56 | echo '<item uid="'${STAMP}'" arg="connectall"><title>Connect All</title><subtitle>Connect to all defined networks</subtitle><icon>icon.png</icon><valid>yes</valid></item>' 57 | 58 | echo '<item uid="'${STAMP}'" arg="disconnectall"><title>Disconnect All</title><subtitle>Disconnect from all connected networks</subtitle><icon>icon.png</icon><valid>yes</valid></item>' 59 | 60 | echo '</items>' 61 | 62 | subtext 63 | Control OpenVPN connections 64 | title 65 | Viscosity 66 | type 67 | 0 68 | withspace 69 | 70 | 71 | type 72 | alfred.workflow.input.scriptfilter 73 | uid 74 | 14D5E084-1B24-4FEC-B287-ADE8530320F2 75 | 76 | 77 | config 78 | 79 | applescript 80 | on alfred_script(query) 81 | tell application "Viscosity" 82 | if query = "connectall" then 83 | connectall 84 | else if query = "disconnectall" then 85 | disconnectall 86 | else 87 | set s to state of first connection where name = query 88 | if s is equal to "Connected" then 89 | disconnect query 90 | else 91 | connect query 92 | end if 93 | end if 94 | end tell 95 | end alfred_script 96 | 97 | 98 | type 99 | alfred.workflow.action.applescript 100 | uid 101 | 58FEBA95-060B-4B7C-9516-2B60011E5A3C 102 | 103 | 104 | uidata 105 | 106 | 14D5E084-1B24-4FEC-B287-ADE8530320F2 107 | 108 | ypos 109 | 200 110 | 111 | 58FEBA95-060B-4B7C-9516-2B60011E5A3C 112 | 113 | ypos 114 | 200 115 | 116 | 117 | webaddress 118 | github.com/andrewschleifer/viscosity-alfredworkflow 119 | 120 | 121 | --------------------------------------------------------------------------------