{"id":149,"date":"2006-08-08T22:12:26","date_gmt":"2006-08-09T03:12:26","guid":{"rendered":"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/08\/08\/com-scripting-with-groovy\/"},"modified":"2006-08-08T22:12:26","modified_gmt":"2006-08-09T03:12:26","slug":"com-scripting-with-groovy","status":"publish","type":"post","link":"http:\/\/juixe.com\/techknow\/index.php\/2006\/08\/08\/com-scripting-with-groovy\/","title":{"rendered":"COM Scripting With Groovy"},"content":{"rendered":"<p>I&#8217;ve mentioned before my use of Groovy in <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/04\/10\/groovy-closures\/\">Groovy Closures<\/a> and <a href=\"http:\/\/www.juixe.com\/techknow\/index.php\/2006\/06\/11\/common-groovy-errors\/\">Common Groovy Errors<\/a>.  I have also mentioned the need to use Visual Basic scripts to open MS Word, or print an HTML document from Internet Explorer.  In this article I will mention how to use Groovy and <b>Scriptom<\/b> to do COM scripting.  Before I integrated with Scriptom I had to write one off Visual Basic scripts and run them from Java by using the  Runtime&#8217;s exec(String) method.  Now I could write the COM script in Groovy.  Here is an example of Groovy code that will open a new Outlook mail message window and populate the To field:<\/p>\n<pre>\nimport org.codehaus.groovy.scriptom.ActiveXProxy\n\ndef outlook = new ActiveXProxy(\"Outlook.Application\");\ndef message = outlook.CreateItem(0);\ndef emails = \"user1@domain1.com;user2@domain2.com\";\ndef rec = message.Recipients.add(emails);\nrec.Type = 1 \/\/ To = 1, CC = 2, BCC = 3\nmessage.Display(true);\n<\/pre>\n<p>You can run this code from the groovyConsole once you have <a href=\"http:\/\/groovy.codehaus.org\/COM+Scripting\">Scriptom<\/a> configured.<\/p>\n<p>Technorati Tags: <a href=\"http:\/\/technorati.com\/tag\/groovy\" rel=\"tag\">groovy<\/a>, <a href=\"http:\/\/technorati.com\/tag\/java\" rel=\"tag\"> java<\/a>, <a href=\"http:\/\/technorati.com\/tag\/gdk\" rel=\"tag\"> gdk<\/a>, <a href=\"http:\/\/technorati.com\/tag\/scriptom\" rel=\"tag\"> scriptom<\/a>, <a href=\"http:\/\/technorati.com\/tag\/activex\" rel=\"tag\"> activex<\/a>, <a href=\"http:\/\/technorati.com\/tag\/com\" rel=\"tag\"> com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve mentioned before my use of Groovy in Groovy Closures and Common Groovy Errors. I have also mentioned the need to use Visual Basic scripts to open MS Word, or print an HTML document from Internet Explorer. In this article I will mention how to use Groovy and Scriptom to do COM scripting. Before I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[15,3,5],"tags":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p902K-2p","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/149"}],"collection":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":0,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"wp:attachment":[{"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/juixe.com\/techknow\/index.php\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}