-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathreveal_file_operator.py
68 lines (46 loc) · 1.86 KB
/
reveal_file_operator.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
import bpy
import platform
import os
def open_explorer(filepath):
# Linux: Linux
# Windows: Windows
# Mac: Darwin
osys = platform.system()
if osys == "Windows":
# Does not work with font folders (explorer issue)
# cmd = f'explorer /select, "{filepath}"'
parent_path = os.path.dirname(filepath)
cmd = f'explorer /select, "{parent_path}"'
elif osys == "Linux":
# --print-reply argument ensures the explorer opens
# Seems when explorer closed, it would only open if called twice
# Printing the reply would called it again i guess
cmd = 'dbus-send --session --print-reply --dest=org.freedesktop.FileManager1 '
cmd += '--type=method_call /org/freedesktop/FileManager1 '
cmd += f'org.freedesktop.FileManager1.ShowItems array:string:"{filepath}" string:""'
elif osys == "Darwin":
# -R argument for reveal --reveal should also work
cmd = f'open -R "{filepath}"'
os.system(cmd)
class FONTSELECTOR_OT_reveal_file(bpy.types.Operator):
"""Reveal file in explorer"""
bl_idname = "fontselector.reveal_file"
bl_label = "Reveal File"
bl_options = {'INTERNAL'}
filepath : bpy.props.StringProperty()
@classmethod
def poll(cls, context):
return True
def execute(self, context):
# Invalid filepath
if not os.path.isfile(self.filepath):
self.report({'WARNING'}, "Invalid filepath")
return {'CANCELLED'}
open_explorer(self.filepath)
self.report({'INFO'}, f"File revealed : {self.filepath}")
return {'FINISHED'}
### REGISTER ---
def register():
bpy.utils.register_class(FONTSELECTOR_OT_reveal_file)
def unregister():
bpy.utils.unregister_class(FONTSELECTOR_OT_reveal_file)