クリップボードの中身を操作する
JavaScriptからは直接クリップボードの中身を操作できないようなので作ってみた。
OSXは比較的簡単に出来たんだけど。
Windowsは少し調べてコードをコピペとかして見たけど、基本的なVBの知識がないのと
席を行ったり来たりがいやになったので未完のまんまです。
var clipboad = function(){ this.contents = ""; this.sys = Folder.fs; if(typeof app.doScript !== 'function'){ //alert('app.doScriptが実装されていません') return { set : function(){return false;}, get : function(){return false;} } } } clipboad.prototype.get = function(){ switch (this.sys){ case 'Macintosh' : return app.doScript("return (the clipboard) as text",ScriptLanguage.APPLESCRIPT_LANGUAGE); case 'Windows' : /* var my_vb = "set ie = CreateObject(\"InternetExplorer.Application\")\n" + "ie.Navigate \"about:blank\"\n" + "Do Until (ie.Busy = False) Or (ie.Document.ReadyState = \"complete\")\n" + "WScript.Sleep 10\n" + "Loop\n" + "return ie.Document.ParentWindow.ClipboardData.GetData(\"Text\")"; return app.doScript(my_vb,ScriptLanguage.visualBasic); */ } return false; } clipboad.prototype.set = function(contents){ if(typeof contents !== 'string'){ switch (typeof contents){ case '' : default : return false; } } switch (this.sys){ case 'Macintosh' : var appScript = "try\r" +"set the clipboard to \"" + contents + "\" as text\r" + "return true\r" + "on error\r" + "return false\r" + "end try"; return app.doScript(appScript , ScriptLanguage.APPLESCRIPT_LANGUAGE); case 'Windows' : /* var my_vb = "set ie = CreateObject(\"InternetExplorer.Application\")\n" + "ie.Navigate \"about:blank\"\n" + "Do Until (ie.Busy = False) Or (ie.Document.ReadyState = \"complete\")\n" + "WScript.Sleep 10\n" + "Loop\n" + "return ie.Document.ParentWindow.ClipboardData.SetData(\"Text\",\""+ contents +"\")"; return app.doScript(my_vb,ScriptLanguage.visualBasic); return; */ } return false; } ////////////////////////////////////////////////////////// ///TEST CB = new clipboad(); //alert(CB.get()); //alert(CB.set(CB)); if(CB.set('TEST'))alert(CB.get());