Skip to content

Instantly share code, notes, and snippets.

@gregoryvit
Last active April 26, 2020 12:07
Show Gist options
  • Select an option

  • Save gregoryvit/e6fcb94df1efede9da4aadf5f535e7b0 to your computer and use it in GitHub Desktop.

Select an option

Save gregoryvit/e6fcb94df1efede9da4aadf5f535e7b0 to your computer and use it in GitHub Desktop.

Revisions

  1. gregoryvit revised this gist Apr 26, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pbpaste_example.py
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,6 @@ def cb_copy(value):
    """
    Writes data to macOS pastboard
    """
    res = os.system("printf '%s' | pbcopy" % value)
    res = os.system(u'printf "%s" | pbcopy' % value.replace('"', '\\"').replace('%', '%%'))
    if res != 0:
    raise(Exception("Exit code: %d" % res))
  2. gregoryvit revised this gist Apr 25, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pbpaste_example.py
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,6 @@ def cb_copy(value):
    """
    Writes data to macOS pastboard
    """
    res = os.system("printf ''%s' | pbcopy" % value)
    res = os.system("printf '%s' | pbcopy" % value)
    if res != 0:
    raise(Exception("Exit code: %d" % res))
  3. gregoryvit revised this gist Apr 25, 2020. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion pbpaste_example.py
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,9 @@ def cb_paste(use_bytes=False):
    stderr=subprocess.PIPE)
    out, err = p.communicate()

    if err:
    raise(Exception(err))

    if not use_bytes:
    return out.decode('utf-8')
    return out
    @@ -19,4 +22,6 @@ def cb_copy(value):
    """
    Writes data to macOS pastboard
    """
    os.system("printf '%s' | pbcopy" % value)
    res = os.system("printf ''%s' | pbcopy" % value)
    if res != 0:
    raise(Exception("Exit code: %d" % res))
  4. gregoryvit created this gist Apr 25, 2020.
    22 changes: 22 additions & 0 deletions pbpaste_example.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    import subprocess
    import os

    def cb_paste(use_bytes=False):
    """
    Returns the data from macOS pastboard
    """
    p = subprocess.Popen(['pbpaste'],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)
    out, err = p.communicate()

    if not use_bytes:
    return out.decode('utf-8')
    return out


    def cb_copy(value):
    """
    Writes data to macOS pastboard
    """
    os.system("printf '%s' | pbcopy" % value)