File: sayclip

package info (click to toggle)
konversation 25.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,364 kB
  • sloc: cpp: 46,929; xml: 779; python: 556; sh: 96; perl: 86; makefile: 7
file content (32 lines) | stat: -rwxr-xr-x 1,042 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
#
# SPDX-FileCopyrightText: 2011 Eike Hein <hein@kde.org>


"""
Used to post the clipboard contents to the current tab in Konversation.

"""

import subprocess

try:
    import konversation.dbus
    import konversation.i18n
    konversation.i18n.init()
except ImportError:
    sys.exit("This script is intended to be run from within Konversation.")

try:
    clipboard = subprocess.check_output((konversation.dbus.dbus_command, 'org.kde.klipper', '/klipper', 'getClipboardContents'))
except subprocess.CalledProcessError:
    konversation.dbus.error(i18n("Unable to retrieve clipboard contents from Klipper."), exit=True)

# Fall back to info if there is no target (usually means we were called from a server tab).
dispatch = konversation.dbus.say if konversation.dbus.target else konversation.dbus.info
    
for line in clipboard.decode(encoding='utf-8', errors='replace').splitlines():
    dispatch(line)