<story><title>JavaScript for OS X Automation</title><url>https://developer.apple.com/library/prerelease/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html</url></story><parent_chain><item><author>andyfleming</author><text>I found this nice simple, contrasting comparison of syntax from the last discussion about this (thought it would be worth sharing).&lt;p&gt;Here is some of the new JavaScript syntax:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  Mail.outgoingMessages.whose({subject:&amp;#x27;JavaScript&amp;#x27;})
&lt;/code&gt;&lt;/pre&gt;
Here is what it looks like in AppleScript&lt;p&gt;&lt;pre&gt;&lt;code&gt;    tell application &amp;quot;Mail&amp;quot;
        set msgs to every outgoing message whose subject is &amp;#x27;JavsScript&amp;#x27;
    end tell
&lt;/code&gt;&lt;/pre&gt;
While the AppleScript sounds logical, the JavaScript syntax just feels so comfortable and familiar (obviously).</text></item></parent_chain><comment><author>Tloewald</author><text>The problem isn&amp;#x27;t the AppleScript&amp;#x27;s wordiness, it&amp;#x27;s that knowing the exact way to phrase a command correctly is horrible (and it doesn&amp;#x27;t help AppleScript is implicitly strongly typed).&lt;p&gt;In HyperTalk you could write something like put 4 + 4, get it; or set fred to 4 + 4; or put 4 + 4 into fred. You could leave quotes off a string, or put quotes on a number, and it would usually &amp;quot;just work&amp;quot;. This made HyperTalk easy for non-programmers to write, yet still easy for programmers to write well (and debug). AppleScript allows even more syntactic constructs than HyperTalk, but they all turn out to be semantically different in incompatible ways. (It&amp;#x27;s very much like they map directly onto C++&amp;#x27;s . -&amp;gt; * and &amp;amp; directly.) So if you can set fred to 4 + 4, you probably can&amp;#x27;t put 4 + 4 into fred. (I&amp;#x27;m pulling these examples out of my ass without looking up actual syntax because I can&amp;#x27;t be bothered.)&lt;p&gt;I went from being a competent HyperTalk programmer to &amp;quot;godlike&amp;quot; thanks to a book by Danny Goodman (The HyperTalk Bible, I think). When AppleScript came out, Apple commissioned Goodman to write the definitive book on AppleScript -- I read it and still couldn&amp;#x27;t get anywhere. AppleScript is kind of like Blender. I can eventually figure out how to do anything, but knowledge of how I did it evaporates almost instantly. It&amp;#x27;s perhaps the worst programming language I have ever actually tried to master.&lt;p&gt;Danny Goodman later wrote books on JavaScript and DHTML which, for their time, were just as great as his HyperTalk stuff, but no-one has ever been able to make AppleScript not suck (for me, anyway).</text></comment>
<story><title>JavaScript for OS X Automation</title><url>https://developer.apple.com/library/prerelease/mac/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/index.html</url></story><parent_chain><item><author>andyfleming</author><text>I found this nice simple, contrasting comparison of syntax from the last discussion about this (thought it would be worth sharing).&lt;p&gt;Here is some of the new JavaScript syntax:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  Mail.outgoingMessages.whose({subject:&amp;#x27;JavaScript&amp;#x27;})
&lt;/code&gt;&lt;/pre&gt;
Here is what it looks like in AppleScript&lt;p&gt;&lt;pre&gt;&lt;code&gt;    tell application &amp;quot;Mail&amp;quot;
        set msgs to every outgoing message whose subject is &amp;#x27;JavsScript&amp;#x27;
    end tell
&lt;/code&gt;&lt;/pre&gt;
While the AppleScript sounds logical, the JavaScript syntax just feels so comfortable and familiar (obviously).</text></item></parent_chain><comment><author>js2</author><text>For a while, there was a wonderful third-party alternative to Applescript known as &amp;quot;appscript&amp;quot;[0]. Your example above in Python would&amp;#x27;ve been:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    app(&amp;#x27;Mail&amp;#x27;).outgoingMessages[its.subject==&amp;#x27;JavaScript&amp;#x27;]
&lt;/code&gt;&lt;/pre&gt;
Appscript also had bindings for Ruby and ObjC.&lt;p&gt;Unfortunately, Apple deprecated the underlying API in 10.6 that made appscript possible and never provided a suitable replacement[1].&lt;p&gt;As always though, the problem wasn&amp;#x27;t Applescript, but rather limited support for Apple Events by applications. Unless that problem is fixed, adding Javascript support to the OSA isn&amp;#x27;t going to help much.&lt;p&gt;[0] &lt;a href=&quot;http://appscript.sourceforge.net/index.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;appscript.sourceforge.net&amp;#x2F;index.html&lt;/a&gt;&lt;p&gt;[1] &lt;a href=&quot;http://appscript.sourceforge.net/status.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;appscript.sourceforge.net&amp;#x2F;status.html&lt;/a&gt;&lt;p&gt;Edited to add: I see the author of appscript has additional criticism linked to elsewhere from this thread - &lt;a href=&quot;https://news.ycombinator.com/item?id=8329408&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;news.ycombinator.com&amp;#x2F;item?id=8329408&lt;/a&gt;</text></comment>