Skip to content

Instantly share code, notes, and snippets.

@toolness
Last active August 29, 2015 14:01
Show Gist options
  • Save toolness/67405092d5fd28119f66 to your computer and use it in GitHub Desktop.
Save toolness/67405092d5fd28119f66 to your computer and use it in GitHub Desktop.
ctypes-based Python version of OS X's pbpaste command for Windows.
import sys
import ctypes
# This is adapted from code found via:
# http://nullege.com/codes/search/ctypes.windll.user32.OpenClipboard
ctypes.windll.user32.OpenClipboard(0)
pcontents = ctypes.windll.user32.GetClipboardData(1) # 1 is CF_TEXT
data = ctypes.c_char_p(pcontents).value
ctypes.windll.user32.CloseClipboard()
if data is not None:
sys.stdout.write(data.replace('\r\n', '\n'))
@toolness
Copy link
Author

The Windows clip.exe program can be used as an alternative to pbcopy, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment