-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbf.py
executable file
·51 lines (39 loc) · 1.18 KB
/
pbf.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
#!python3
import typer
from icecream import ic
from loguru import logger
from rich.console import Console
from pathlib import Path
from AppKit import NSPasteboard, NSFilenamesPboardType, NSArray
console = Console()
app = typer.Typer(no_args_is_help=True)
@app.command()
def copy(file: Path):
"""Copy file to clipboard only on macos"""
if not file.exists():
ic("File does not exist")
return
pb = NSPasteboard.generalPasteboard()
pb.clearContents()
file_path = str(file.resolve())
ic(file_path)
array = NSArray.arrayWithObject_(file_path)
pb.declareTypes_owner_([NSFilenamesPboardType], None)
pb.setPropertyList_forType_(array, NSFilenamesPboardType)
pb.writeObjects_(array)
ic(pb.types())
def dump():
pb = NSPasteboard.generalPasteboard()
# Loop through all types and print out their corresponding content
types = pb.types()
for pboard_type in types:
content = pb.stringForType_(pboard_type)
ic(f"Content for type {pboard_type}:", content)
types = pb.types()
ic("Available types:", types)
@logger.catch()
def app_wrap_loguru():
app()
if __name__ == "__main__":
ic("main")
app_wrap_loguru()