类Mac系统Spotlight搜索软件albert

介绍

什么是albert?

一款类似于Mac系统Spotlight搜索的软件

官方网站:https://albertlauncher.github.io/

代码仓库:https://github.com/albertlauncher/albert

安装

1
2
3
4
5
6
wget -nv https://download.opensuse.org/repositories/home:manuelschneid3r/xUbuntu_16.04/Release.key -O Release.key
sudo apt-key add - < Release.key
sudo apt-get update
sudo sh -c "echo 'deb http://download.opensuse.org/repositories/home:/manuelschneid3r/xUbuntu_16.04/ /' > /etc/apt/sources.list.d/albert.list"
sudo apt-get update
sudo apt-get install albert

修改配置文件

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
[General]
frontendId=org.albert.frontend.boxmodel.widgets
hotkey=Alt+Space
showTray=true
standsalone_note_shown=true
terminal=gnome-terminal -x

[org.albert.extension.applications]
enabled=true
fuzzy=true

[org.albert.extension.calculator]
enabled=true

[org.albert.extension.chromebookmarks]
enabled=true

[org.albert.extension.externalextensions]
enabled=true

[org.albert.extension.files]
enabled=true
filters=inode/directory, application/*, text/*, image/*
fuzzy=true

[org.albert.extension.firefoxbookmarks]
enabled=true
profile=Profile0

[org.albert.extension.hashgenerator]
enabled=true

[org.albert.extension.kvstore]
enabled=true

[org.albert.extension.mpris]
enabled=true

[org.albert.extension.ssh]
enabled=true

[org.albert.extension.system]
enabled=true

[org.albert.extension.terminal]
enabled=true

[org.albert.extension.websearch]
enabled=true

[org.albert.frontend.boxmodel.qml]
alwaysOnTop=true
hideOnClose=false
hideOnFocusLoss=true
showCentered=true
stylePath=/usr/share/albert/org.albert.frontend.boxmodel.qml/styles/BoxModel/MainComponent.qml
windowPosition=@Point(609 297)

[org.albert.frontend.boxmodel.widgets]
alwaysOnTop=true
clearOnHide=false
displayIcons=true
displayScrollbar=true
displayShadow=true
hideOnClose=false
hideOnFocusLoss=true
itemCount=10
showCentered=true
theme=Yosemite

添加switchapp插件

保存目录:

1
~/.local/share/albert/org.albert.extension.externalextensions/extensions/

文件内容:

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
#!/usr/bin/env python

import subprocess
import sys
import re
import os
import json
from ConfigParser import SafeConfigParser

"""
A window switcher that opens existing applications
requires: wmctrl
"""

albert_op = os.environ.get('ALBERT_OP')
APP_DIR = "/usr/share/applications/"
LOCAL_APP_DIR = os.path.expanduser("~/.local/share/applications/")

if albert_op == 'METADATA':
metadata = """{
"iid": "org.albert.extension.external/v3.0",
"name": "WindowSwitcher",
"version": "1.0",
"author": "Klesh Wong",
"dependencies": [],
"trigger": "`"
}"""
print(metadata)
sys.exit(0)

elif albert_op == 'QUERY':
def parse_config_file(program):
config_file = ""
parts = program.split('.')

for part in parts:
if os.path.exists(APP_DIR + part + ".desktop"):
config_file = APP_DIR + part + ".desktop"
break

if os.path.exists(LOCAL_APP_DIR + part + ".desktop"):
config_file = LOCAL_APP_DIR + part + ".desktop"
break

part = part.lower()
if os.path.exists(APP_DIR + part + ".desktop"):
config_file = APP_DIR + part + ".desktop"
break

if os.path.exists(LOCAL_APP_DIR + part + ".desktop"):
config_file = LOCAL_APP_DIR + part + ".desktop"
break

if config_file == "":
return ["", ""]
else:
parser = SafeConfigParser()
parser.read(config_file)
return [parser.get("Desktop Entry", "Name"),
parser.get("Desktop Entry", "Icon")]

albert_query = os.environ.get('ALBERT_QUERY')
if albert_query:
albert_query = albert_query[1:]

process = subprocess.Popen(['wmctrl', '-lpx'], stdout=subprocess.PIPE)
output, error = process.communicate()
if error:
print error
sys.exit(1)
items = []
patt = re.compile(r'^(\w+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.+)$')
for line in output.split('\n'):
match = patt.match(line)
if not match:
continue

name, icon = parse_config_file(match.group(4))

window_name = match.group(6)

search_str = (name + " " + window_name).lower()

if not name:
name = window_name

description = window_name

if albert_query and albert_query not in search_str:
continue

item = {
'id': match.group(1),
'name': name,
'icon': icon,
'description': description,
'completion': 'switched',
'actions': [{
'name': 'Activiate',
'command': 'python',
'arguments': [
__file__,
str(match.group(1))
]
}]
}

items.append(item)

resp = {
'items': items
}
text = json.dumps(resp)
print(text)

if len(sys.argv) > 1:
window_id = sys.argv[1]
subprocess.Popen(['wmctrl', '-ia', window_id])