Skip to content

Commit 82faa88

Browse files
zakialibaxen
authored andcommitted
fix: Resize file in screen toolkit (#81)
Co-authored-by: Bradley Axen <[email protected]>
1 parent b03ba54 commit 82faa88

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/goose/toolkit/screen.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
import subprocess
22
import uuid
33

4+
from rich.markdown import Markdown
5+
from rich.panel import Panel
6+
47
from goose.toolkit.base import Toolkit, tool
58

69

710
class Screen(Toolkit):
811
"""Provides an instructions on when and how to work with screenshots"""
912

1013
@tool
11-
def take_screenshot(self) -> str:
14+
def take_screenshot(self, display: int = 1) -> str:
1215
"""
13-
Take a screenshot to assist the user in debugging or designing an app. They may need help with moving a screen element, or interacting in some way where you could do with seeing the screen.
16+
Take a screenshot to assist the user in debugging or designing an app. They may need
17+
help with moving a screen element, or interacting in some way where you could do with
18+
seeing the screen.
1419
15-
Return:
16-
(str) a path to the screenshot file, in the format of image: followed by the path to the file.
20+
Args:
21+
display (int): Display to take the screen shot in. Default is the main display (1). Must be a value greater than 1.
1722
""" # noqa: E501
1823
# Generate a random tmp filename for screenshot
19-
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.png"
24+
filename = f"/tmp/goose_screenshot_{uuid.uuid4().hex}.jpg"
25+
screen_capture_command = ["screencapture", "-x", "-D", str(display), filename, "-f", "jpg"]
26+
27+
subprocess.run(screen_capture_command, check=True, capture_output=True)
28+
29+
resize_command = ["sips", "--resampleWidth", "768", filename, "-s", "format", "jpeg"]
30+
subprocess.run(resize_command, check=True, capture_output=True)
2031

21-
subprocess.run(["screencapture", "-x", filename])
32+
self.notifier.log(
33+
Panel.fit(
34+
Markdown(f"```bash\n{' '.join(screen_capture_command)}"),
35+
title="screen",
36+
)
37+
)
2238

2339
return f"image:{filename}"
2440

0 commit comments

Comments
 (0)