MCPcopy Create free account
hub / github.com/danielmiessler/Fabric / get_clipboard_content

Function get_clipboard_content

scripts/python_ui/streamlit.py:1252–1315  ·  view source on GitHub ↗

Get content from clipboard with proper error handling. Returns: Tuple[bool, str, str]: (success, content, error_message)

()

Source from the content-addressed store, hash-verified

1250
1251
1252def get_clipboard_content() -> Tuple[bool, str, str]:
1253 """Get content from clipboard with proper error handling.
1254
1255 Returns:
1256 Tuple[bool, str, str]: (success, content, error_message)
1257 """
1258 try:
1259 # macOS - use pbpaste
1260 if PLATFORM == "darwin":
1261 result = run(["pbpaste"], capture_output=True, text=True, check=True)
1262 # Windows - fallback to pyperclip if available
1263 elif PLATFORM == "win32":
1264 try:
1265 import pyperclip
1266
1267 content = pyperclip.paste()
1268 return True, content, ""
1269 except ImportError:
1270 return (
1271 False,
1272 "",
1273 "The pyperclip module is required for clipboard operations on Windows.\nPlease install it with: pip install pyperclip",
1274 )
1275 except Exception as e:
1276 return False, "", f"Windows clipboard error: {str(e)}"
1277 # Linux - use xclip
1278 else:
1279 result = run(
1280 ["xclip", "-selection", "clipboard", "-o"],
1281 capture_output=True,
1282 text=True,
1283 check=True,
1284 )
1285
1286 content = result.stdout
1287 # Validate the content is proper UTF-8
1288 try:
1289 content.encode("utf-8").decode("utf-8")
1290 return True, content, ""
1291 except UnicodeError:
1292 return False, "", "Clipboard contains invalid Unicode characters"
1293 except FileNotFoundError:
1294 if PLATFORM == "darwin":
1295 return (
1296 False,
1297 "",
1298 "Could not access clipboard. Please ensure you have the proper permissions.",
1299 )
1300 elif PLATFORM == "win32":
1301 return (
1302 False,
1303 "",
1304 "Windows clipboard access failed. Try installing pyperclip with: pip install pyperclip",
1305 )
1306 else:
1307 return (
1308 False,
1309 "",

Callers 1

mainFunction · 0.85

Calls 1

runFunction · 0.85

Tested by

no test coverage detected