WSH よりクリップボードを使う
最近のバージョンの IE ではセキュリティが厳しくなったためこの手法は使いづらくなりました。
[WSH よりクリップボード、次の手] も参照してみてください。(2010.10.08)
WSH よりクリップボードにアクセスすることはできない。しかし、調べてみたところ、Internet Explorer がクリップボードにアクセスするためのインターフェースを公開していることがわかった(常套手段?)。
そんなわけで、文字列をコピー & 取得する部分をクラス化した。
使い方はこんな感じで。
var clipboard = new Clipboard (); var s = clipboard.getText (); WScript.Echo (s); clipboard.setText (s.replace (/my/gi, "Your"));
function Clipboard () { // IE のインスタンスを作成 this.internetExplorer = new ActiveXObject ('InternetExplorer.Application'); // IEの初期化 this.internetExplorer.Navigate ('about:blank'); while (this.internetExplorer.Busy) WScript.Sleep (10); // クリップボードを取得 this.clipboard = this.internetExplorer.Document.parentWindow.clipboardData; // クリップボードより文字列を取得するメソッド this.getText = function () { return this.clipboard.getData ('text'); }; // クリップボードに文字列をコピーするメソッド this.setText = function (s) { this.clipboard.setData ('text', s); return true; } // IE を解放するメソッド this.release = function () { this.internetExplorer.Quit (); return true; } return this; }
トラックバック
- このエントリーにトラックバック:
- http://frog.raindrop.jp/cgi-bin/mt/mt-tb.cgi/828
コメント