クリップボード操作コマンドxsel、putclip

最近ちゃんと投稿できていなかったので反省。

linux上でクリップボードを定期的にチェックしたかったので、groovyで。

動作確認はしてないけど、windowsにcygwinはいっていたら動くかも。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17

#!/usr/bin/env groovy
import static javax.swing.JOptionPane.*

def oldclip = ""
new Thread({
    final def COMMAND=(System.properties."os.name" ==~ /.*(?i)linux.*/)?"xsel -b -o":"cmd.exe /c getclip"
    oldclip = COMMAND.execute().text
    while(true){
        def clip = COMMAND.execute().text
        if( clip != oldclip && clip ==~ /.*(?i)groovy.*/ ){
            showMessageDialog( null, "groovy関連の情報をコピペした?" )
            oldclip = clip
        }
        Thread.sleep(500)
    }
} as Runnable).start()