Skip to content

Commit d170fdc

Browse files
committed
support macos clipboard
1 parent fd4ac18 commit d170fdc

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sys
2+
3+
4+
def copy_html_to_clipboard(html_content):
5+
if sys.platform != "darwin":
6+
raise NotImplementedError("This function is only implemented for MacOS.")
7+
8+
from AppKit import NSPasteboard, NSStringPboardType
9+
from Foundation import NSString
10+
11+
pb = NSPasteboard.generalPasteboard()
12+
pb.clearContents()
13+
nshtml = NSString.stringWithString_(html_content)
14+
# Use the public.html UTI for HTML content:
15+
pb.declareTypes_owner_(["public.html"], None)
16+
pb.setString_forType_(nshtml, "public.html")
17+
print("Copied as formatted HTML (macOS)")

AgentCrew/modules/gui/widgets/message_bubble.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,16 @@ def _copy_as_html(self):
366366
doc.setHtml(html_content)
367367
if sys.platform == "win32":
368368
from AgentCrew.modules.gui.utils.wins_clipboard import (
369-
copy_html_to_clipboard,
369+
copy_html_to_clipboard as win_copy_html,
370370
)
371371

372-
copy_html_to_clipboard(doc.toHtml(), self.raw_text)
372+
win_copy_html(doc.toHtml(), self.raw_text)
373+
elif sys.platform == "darwin":
374+
from AgentCrew.modules.gui.utils.macos_clipboard import (
375+
copy_html_to_clipboard as macos_copy_html,
376+
)
377+
378+
macos_copy_html(doc.toHtml())
373379
else:
374380
pyperclip.copy(doc.toHtml())
375381

@@ -423,10 +429,16 @@ def _copy_selected_html(self):
423429

424430
if sys.platform == "win32":
425431
from AgentCrew.modules.gui.utils.wins_clipboard import (
426-
copy_html_to_clipboard,
432+
copy_html_to_clipboard as win_copy_html,
433+
)
434+
435+
win_copy_html(selected_html, selected_plain_text)
436+
elif sys.platform == "darwin":
437+
from AgentCrew.modules.gui.utils.macos_clipboard import (
438+
copy_html_to_clipboard as macos_copy_html,
427439
)
428440

429-
copy_html_to_clipboard(selected_html, selected_plain_text)
441+
macos_copy_html(selected_html)
430442
else:
431443
pyperclip.copy(selected_html)
432444
except Exception:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies = [
4343
"voyageai>=0.3.2",
4444
"numpy>=1.24.4,<2; python_version < '3.13' and sys_platform == 'darwin'",
4545
"pywin32; sys_platform == 'win32'",
46+
"pyobjc; sys_platform == 'darwin'",
4647
"rapidocr-onnxruntime>=1.4.4",
4748
"a2a-sdk>=0.2.9",
4849
"qtawesome>=1.4.0",

0 commit comments

Comments
 (0)