-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathConnectionSearcher.py
executable file
·137 lines (111 loc) · 3.69 KB
/
ConnectionSearcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import json
import os
import plistlib
import sys
from workflow import ICON_WARNING, MATCH_SUBSTRING, Workflow3
def read_connections():
# Read preferences file
preferences_path = os.path.join(
os.environ["HOME"],
"Library",
"Containers",
"com.p5sys.jump.mac.viewer",
"Data",
"Library",
"Preferences",
"com.p5sys.jump.mac.viewer.plist",
)
# if preference path not exists, try this location:
if not os.path.isfile(preferences_path):
preferences_path = os.path.join(
os.environ["HOME"],
"Library",
"Preferences",
"com.p5sys.jump.mac.viewer.web.plist",
)
# try setapp jump desktop
if not os.path.isfile(preferences_path):
preferences_path = os.path.join(
os.environ["HOME"],
"Library",
"Preferences",
"com.p5sys.jumpdesktop-setapp.plist",
)
connections = []
with open(preferences_path, "rb") as fp:
plist = plistlib.load(fp)
# Extract profile data from plist
connection_path = plist.get("path where JSON .jump files are stored")
if connection_path is None:
connection_path = "~/Documents/JumpDesktop/Viewer/Servers"
connection_path = os.path.normpath(os.path.expanduser(connection_path))
jumps = glob.glob(connection_path + "/Computer - *.jump")
connections = []
for jump in jumps:
f = open(jump)
json_content = f.read()
f.close()
dict_content = json.loads(json_content)
icon = None
if dict_content["Icon"]:
icon = (
"/Applications/Jump Desktop.app/Contents/Resources/%s.png"
% dict_content["Icon"]
)
username = ""
if "Username" in dict_content:
username = dict_content["Username"]
command = "jump://?protocol=%s&host=%s&username=%s" % (
protocol_switch(dict_content["ProtocolTypeCode"]),
dict_content["TcpHostName"],
username,
)
connections.append(
{
"name": dict_content["DisplayName"],
"command": command,
"path": jump,
"icon": icon,
"tags": dict_content["Tags"],
}
)
return connections
def protocol_switch(x):
return {
0: "rdp",
1: "vnc",
2: "fluid",
}.get(x, 0)
def filter_key_for_connection(connection):
return connection["name"] + " " + str(connection["tags"])
def sort_key_for_connection(connection):
return connection["name"]
def main(wf: Workflow3):
connections = wf.cached_data("connections", read_connections, max_age=30)
# Query argument Ensure `query` is initialised
query = None
if len(wf.args):
query = wf.args[0]
connections = wf.filter(
query, connections, filter_key_for_connection, match_on=MATCH_SUBSTRING
)
if not connections:
wf.add_item("No connection matches", icon=ICON_WARNING)
connections.sort(key=sort_key_for_connection)
for connection in connections:
wf.add_item(
title=connection["name"],
subtitle=((str(connection["tags"]) + " ") if connection["tags"] else "")
+ connection["command"],
arg=connection["path"],
valid=True,
icon=connection["icon"],
)
wf.send_feedback()
return
if __name__ == "__main__":
wf = Workflow3()
sys.exit(wf.run(main))