截图时重用己存在的 KSnapshot

legnaleurc | 2011/07/30

在 Debian 或 Kubuntu 的预设设定, 按下 PrintScreen 键会运行 KSnapshot, 若再按下一次 PrintScreen, 则会再唤起一个 KSnapshot. 但这不是我想要的行为, 当我按下PrintScreen 时就代表我想抓图了, 不停地运行新的 KSnapshot 有点蠢. 幸好 KSnapshot 有提供足够的 D-Bus 介面, 这让我们可以写一个 script 操作已存在的 KSnapshot.

#! /bin/sh

PID=`pidof -s ksnapshot`

if [ -z ${PID} ] ; then
    `which ksnapshot` -caption KSnapshot &
    exit 0
fi

DBUS_SERVICENAME="org.kde.ksnapshot-${PID}"
DBUS_PATH='/KSnapshot'
DBUS_METHOD='slotGrab'

qdbus ${DBUS_SERVICENAME} ${DBUS_PATH} ${DBUS_METHOD}

接着修改 System Settings 里的 Input Action, 把 PrintScreen 对应的命令改成上面那个 script 的路径即可.

System Settings

System Settings

原文链结: Reuse existing KSnapshot on press PrintScreen

    Tags: ,

    10 FEEDBACKS

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Note: Commenter is allowed to use '@User+blank' to automatically notify your reply to other commenter. e.g, if ABC is one of commenter of this post, then write '@ABC '(exclude ') will automatically send your comment to ABC. Using '@all ' to notify all previous commenters. Be sure that the value of User should exactly match with commenter's name (case sensitive).

    This site uses Akismet to reduce spam. Learn how your comment data is processed.