{"id":315,"date":"2011-08-11T11:30:01","date_gmt":"2011-08-11T10:30:01","guid":{"rendered":"http:\/\/www.floyd.ch\/?p=315"},"modified":"2023-05-31T08:49:35","modified_gmt":"2023-05-31T07:49:35","slug":"automating-jd-gui-decompilation-on-a-mac-with-applescript","status":"publish","type":"post","link":"https:\/\/www.floyd.ch\/?p=315","title":{"rendered":"Automating JD-GUI decompilation on a Mac with AppleScript"},"content":{"rendered":"<p>I know the guys over at <a title=\"Java Decompiler\" href=\"https:\/\/java-decompiler.github.io\/\">Java Decompiler<\/a> don&#8217;t want to release a command line tool, because they fear that companies will use their code in commercial product. See the <a title=\"releasing jd-core\" href=\"https:\/\/web.archive.org\/web\/20101204040838\/http:\/\/java.decompiler.free.fr\/?q=node\/116\">discussion here<\/a>. I found a solution to my problem, so that I can still automate the decompilation process. During my Android research I really need to decompile a lot of jar files, therefore I wrote a simple AppleScript that saves me the sources to my \/opt folder.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ntell application &quot;JD-GUI&quot;\r\n\tactivate\r\nend tell\r\n\r\ntell application &quot;System Events&quot;\r\n\tkeystroke &quot;s&quot; using {command down, option down}\r\nend tell\r\ntell application &quot;System Events&quot;\r\n\tkeystroke tab\r\n\tkeystroke tab\r\n\tkeystroke tab\r\n\tkey code 125 #Down\r\n\tkey code 125 #Down\r\n\tkey code 125 #Down\r\n\tkey code 125 #Down\r\n\tkey code 125 #Down\r\n\tkey code 36 #Enter\r\n\tdelay 1\r\n\tkey code 36 #Enter\r\n\tdelay 2\r\nend tell\r\n\r\nrepeat while appIsRunning(&quot;JD-GUI&quot;)\r\n\ttell application &quot;System Events&quot;\r\n\t\tkeystroke &quot;q&quot; using {command down} #Close JD-GUI\r\n\tend tell\r\n\tdelay 2\r\nend repeat\r\n\r\non appIsRunning(appName)\r\n\ttell application &quot;System Events&quot; to (name of processes) contains appName\r\nend appIsRunning\r\n<\/pre>\n<p>After saving the script as decompile_jar.applescript with the AppleScript Editor, you can invoke it from your bash script like this:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n\/Applications\/JD-GUI.app\/Contents\/MacOS\/jd-gui example.jar &amp;\r\nsleep 1\r\nosascript decompile_jar.applescript\r\nmv \/opt\/example.src.zip \/your\/destination\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I know the guys over at Java Decompiler don&#8217;t want to release a command line tool, because they fear that companies will use their code in commercial product. See the discussion here. I found a solution to my problem, so &hellip; <a href=\"https:\/\/www.floyd.ch\/?p=315\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,19],"tags":[29,28,27,26],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-coding","category-useful-scripts","tag-applescript","tag-decompiling","tag-jd-gui","tag-mac"],"_links":{"self":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":12,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":1372,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions\/1372"}],"wp:attachment":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}