クリップボードにアクセスするスクリプト
wsf(wsh)のJavascriptでクリップボードにアクセスする方法を
web検索したら、
WSH よりクリップボードを使う
WSH よりクリップボード、次の手
が見つかりました。
前者は、いちいちダイアログが立ち上がるので
後者を使いたいわけですが、CライクだからJavaScriptを使う
私にはとっかかりの部分がよくわかりません。
で、自分がとっつきやすいようにするため、二つをあわせて
以下のように変更(ほとんどパクリですみません)。とりあえず動作。
<?xml version="1.0" encoding="Shift_JIS" standalone="yes" ?>
<package>
<job id="ClipTest">
<?job error="True" debug="True" ?>
<object id="objFs" progid="Scripting.FileSystemObject" />
<script language="JavaScript">
<![CDATA[var clipboard = new Clipboard ();
var stxt = clipboard.getText ();
WScript.Echo (stxt);//クリップボードの内容をダイアログ表示clipboard.setText ("OK : " + stxt);//"OK : "を追加して文字列をクリップボードに書き込み
function Clipboard ()
{
// コマンドのID
var OLECMDID_COPY = 12;
var OLECMDID_PASTE = 13;
var OLECMDID_SELECTALL = 17;
// IE のインスタンスを作成
this.internetExplorer = new ActiveXObject ('InternetExplorer.Application');
// IEの初期化
this.internetExplorer.Navigate ('about:blank');
while (this.internetExplorer.Busy)
WScript.Sleep (10);
// textarea 要素を作成する
var _textarea = this.internetExplorer.document.createElement ("textarea");
this.internetExplorer.document.body.appendChild (_textarea);
_textarea.focus ();// クリップボードより文字列を取得するメソッド
this.getText = function ()
{
_textarea.innerText = "";
this.internetExplorer.execWB (OLECMDID_PASTE, 0);
return _textarea.innerText;
};
// クリップボードに文字列をコピーするメソッド
this.setText = function (s)
{
_textarea.innerText = s;
this.internetExplorer.execWB (OLECMDID_SELECTALL, 0);
this.internetExplorer.execWB (OLECMDID_COPY, 0);
return true;
}
// IE を解放するメソッド
this.release = function ()
{
this.internetExplorer.Quit ();
return true;
}
return this;
}
]]>
</script>
</job>
</package>
| 固定リンク
| コメント (2)
| トラックバック (0)