-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotlight.lua
84 lines (72 loc) · 2.9 KB
/
spotlight.lua
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
--
--
-- Alternative for Apple Spotlight
--
local fu = require("fileutils")
local util = require("utils")
local reloadApplication = { text = "Reload applications", uuid = "reload" }
local finderApplication = {
text = "Finder",
uuid = "Finder",
image = hs.image.imageFromAppBundle("com.apple.finder")
}
local intellijLibraryVersion = "IntelliJIdea2023.3"
local intellijAppLocation = "//Users/tvs/Applications/IntelliJ IDEA Ultimate.app"
local chooseApplication
function buildApplicationChoices(directory)
local applications = util:split(hs.execute("ls " .. directory), "\n")
local result = {}
for _, application in pairs(applications) do
table.insert(result, {
text = string.gsub(application, ".app", ""),
uuid = application,
image = hs.image.imageFromMediaFile(directory .. "/" .. application)
})
end
return result
end
function initializeApplicationChoices()
local applicationChoices = { finderApplication }
util:addToTable(applicationChoices, buildApplicationChoices("/Applications"))
util:addToTable(applicationChoices, buildApplicationChoices("/System/Applications"))
util:addToTable(applicationChoices, buildApplicationChoices("/System/Applications/Utilities"))
util:addToTable(applicationChoices, findIntellijProjects())
table.insert(applicationChoices, reloadApplication)
return applicationChoices
end
function findIntellijProjects()
local projects = {}
local path = hs.fs.pathToAbsolute("~/Library/Application Support/JetBrains/" .. intellijLibraryVersion .. "/options/recentProjects.xml")
if not path then
return {}
end
local recentProjectsFile = fu:read_file(path)
for match in recentProjectsFile:gmatch "entry key=\".-\"" do
local projectLocation = string.gsub(string.gsub(match, "entry key=\"$USER_HOME%$", ""), "\"", "")
local projectName = string.gsub(projectLocation, projectLocation:match(".*/"), "")
table.insert(projects, {
text = "idea " .. projectName,
uuid = "idea " .. "~" .. projectLocation,
image = hs.image.imageFromMediaFile(intellijAppLocation)
})
end
util:reverse(projects)
return projects
end
function onCompletionHandler(result)
if not result then
return
end
if result.uuid == reloadApplication.uuid then
chooseApplication:choices(initializeApplicationChoices())
elseif result.uuid:find("idea ") == 1 then
fu:execute_command("/usr/local/bin/" .. result.uuid)
end
hs.application.launchOrFocus(result.uuid)
end
chooseApplication = hs.chooser.new(onCompletionHandler)
:placeholderText("Search apps")
:choices(initializeApplicationChoices())
:rows(4)
hs.hotkey.bind(cah, "space", util:bind(chooseApplication, "show"))
hs.hotkey.bind({ "cmd" }, "space", util:bind(chooseApplication, "show"))