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)
|