title: How do I choose JavaScript for my AppleScript SCPT file?
body: <p>I'm calling an Applescript scpt file and when I opened the AppleScript editor it had an option to use JavaScript. </p>
  
  <p>I would like to convert my AppleScript to JavaScript but can't find any documentation on it (announcements and such and redirects on apple). </p>
  
  <p>Here is my AppleScript: </p>
  
  <pre><code>#!/usr/bin/osascript
  
  on run argv
  
      set output to "{\"1st Parameter\":\"" &amp; first item of argv &amp; "\"}"
      return output
  
  end run
  </code></pre>
  
  <p><strong>More context:</strong></p>
  
  <p>I'm trying to loop through a directory and export from Excel. I only need to know about how to run JavaScript in a SCPT file but this is the background. </p>
  
  <pre><code>#!/usr/bin/osascript
  
  on run argv
  
      #goal is to export multiple files to csv
      #the plan is to
      #pass in folder and loop through files or 
      #pass in array of files (paths as a comma separated string)
      #pass in single file and call script multiple times
      set processReportsScript to "excel -e '" &amp; first item of argv &amp; "'  '" -o '" &amp; second item of argv &amp; "'.csv'"
  
      do shell script processReportsScript
  
  end run
  </code></pre>
  
  <p><strong>UPDATE:</strong> </p>
  
  <p>While in <strong>Script Editor</strong> I'm able to run this <strong>JavaScript</strong>: </p>
  
  <pre><code>function run(args) {
    var x = false;
    var y = Application("Mail");
    var running = y.running();
    var id = y.id();
  
    debugger;
  
    if (x) { 
      console.log("Why isn't this being called?")
    }
  
    return "hello";
  }
  </code></pre>
  
  <p>Based in part on this <a href="https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-11.html" rel="nofollow noreferrer">guide</a>.</p>
  
  <p>However when I save the JavaScript into the SCPT file and call it from an external application it gives the following error: </p>
  
  <blockquote>
    <p>script error: Expected end of line, etc. but found “(”. (-2741)</p>
  </blockquote>
  
  <p>It does not give any errors when using AppleScript. </p>
  
  <p>FYI the external application is passing the script to <strong>osascript</strong>. </p>
  
  <p><strong>UPDATE 2:</strong> </p>
  
  <p>I changed the extension from scpt to js and now it's running. I read that it's possible to pass in the language type using -l but when I do I get numerous variations of the error: </p>
  
  <blockquote>
    <p>no such component " 'JavaScript'"
    no such component " JavaScript"</p>
  </blockquote>
  
  <p>As long as it works by changing the extension I think this works. </p>