システムユーザーサービスはxclipコマンドをどのように実行しますか?

システムユーザーサービスはxclipコマンドをどのように実行しますか?

数秒使用した後、自動的にクリップボードを消去したいと思います。

#!/usr/bin/env bash

LOCKFILE=/tmp/.clearclip-lock
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
  exit 1
fi
trap "rm -f ${LOCKFILE}; exit" INT TERM EXIT
touch ${LOCKFILE}
echo $$ > ${LOCKFILE}

if xclip -o -selection clipboard 1>&2 2>/dev/null; then
  if watch -n 0.5 -t --chgexit xclip -o -selection clipboard @>/dev/null; then
    sleep 10
    xsel -bc
  fi
fi

rm -f ${LOCKFILE}

私はちょうどこのおおよその実行可能ファイル操作を開始し、~/mypath/clearclipユーザーローカルシステムタイマーを使用して実行したいと思います。それにもかかわらず、サービスでエラーが発生します。Error opening terminal: unknown.

# ~/.local/share/systemd/user/clearclip.service
[Unit]
Description=clear the clipboard
ConditionFileIsExecutable=%h/_path/clearclip.sh

[Service]
Environment=DISPLAY=:0
ExecStart=%h/_path/clearclip.sh
Type=oneshot

私の主な質問は次のとおりです。

同じ機能を実行しますが、非対話式で実行するツールはありますかwatch -g?あなたのアプローチは何ですか?出力を比較したり、期待どおりに復元したり、他のタスクを実行したりするために、whileループでtmpファイルに出力を書きますか?

もう一つの質問:デュアルタイマー設定はどのように見えますか?

たとえば、タイマーはクリップボードが変更されるタイミングを確認し、クリップボードの選択をクリアする他のタイマーをトリガー(または再開)します。

2018年7月25日に修正:

今週、私はユーザータイマーでこのスクリプトを使用することをあきらめました。opening terminalエラーを取り除くために端末をエミュレートするためにzptyを使用していますが、最終的にclearclip &~/.config/zsh/.zlogin

#!/usr/bin/env zsh
# zmodload zsh/zpty

oclip=""
let count='-1'
let timeout=70

clipchanged() {
  if ! xclip -o -selection clipboard 2>/dev/null 1>&2; then
    count='-1'
    return 1
  fi
  clip="$(xclip -o -selection clipboard)"
  if [[ -z "$clip" ]] || [[ "$oclip" == "$clip" ]]; then
    return 1
  elif [[ -z "$oclip" ]]; then
    oclip="$clip"
    return 1
  else
    (( count=timeout ))
    oclip="$clip"
    return 0
  fi
}

while true; do
  if (( count > 0 )); then
    ((count--))
    # echo -n "\r\033[K$count"
  fi
  if (( count == 0 )); then
    xsel -bc
  fi
  if clipchanged; then
    (( count=timeout ))
  fi
  sleep .5
done

2020年9月7日に修正:

タイトルに適切な質問を追加しましたが、すぐにアイデアを放棄しました。クリップボードを消去したり、変更内容に対処するには、--watch次のオプションを使用しますwl-copy(1)

--watch command...
    Instead of pasting once and exiting, continuously watch the clipboard for changes, and run the specified command each time a new selection appears. The spawned process can read the clipboard contents from its standard input. This mode requires a compositor that supports the wlroots data-control protocol.

ベストアンサー1

おすすめ記事