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

Function get_clipboard_content

scripts/python_ui/streamlit.py:1253–1316  ·  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

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

Callers 1

mainFunction · 0.85

Calls 1

runFunction · 0.85

Tested by

no test coverage detected