forked from talonhub/community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finder.py
77 lines (61 loc) · 2.03 KB
/
finder.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
import os
from talon import Context, actions, ui
from talon.mac import applescript
ctx = Context()
ctx.matches = r"""
app: finder
"""
directories_to_remap = {"": "/Volumes"}
directories_to_exclude = {}
@ctx.action_class("user")
class UserActions:
def file_manager_open_parent():
actions.key("cmd-up")
def file_manager_current_path():
title = ui.active_window().title
if "~" in title:
title = os.path.expanduser(title)
if title in directories_to_remap:
title = directories_to_remap[title]
if title in directories_to_exclude:
title = ""
return title
def file_manager_terminal_here():
applescript.run(
r"""
tell application "Finder"
set myWin to window 1
set thePath to (quoted form of POSIX path of (target of myWin as alias))
tell application "Terminal"
activate
tell window 1
do script "cd " & thePath
end tell
end tell
end tell"""
)
def file_manager_show_properties():
"""Shows the properties for the file"""
actions.key("cmd-i")
def file_manager_open_directory(path: str):
"""opens the directory that's already visible in the view"""
actions.key("cmd-shift-g")
actions.sleep("50ms")
actions.insert(path)
actions.key("enter")
def file_manager_select_directory(path: str):
"""selects the directory"""
actions.insert(path)
def file_manager_new_folder(name: str):
"""Creates a new folder in a gui filemanager or inserts the command to do so for terminals"""
actions.key("cmd-shift-n")
actions.insert(name)
def file_manager_open_file(path: str):
"""opens the file"""
actions.key("home")
actions.insert(path)
actions.key("cmd-o")
def file_manager_select_file(path: str):
"""selects the file"""
actions.key("home")
actions.insert(path)