title: How do I get the name of the newest file via the Terminal?
body: <p>I'm trying to create a macro for <a href="http://www.keyboardmaestro.com/main/" rel="noreferrer">Keyboard Maestro</a> for OS X doing the following:</p>
  
  <ol>
  <li>Get name of newest file in a directory on my disk based on date created;</li>
  <li>Paste the text "newest file: " plus the name of the newest file.</li>
  </ol>
  
  <p>One of its options is to "Execute a shell script", so I thought that would do it for 1. After Googling around a bit I came up with this:</p>
  
  <pre><code>cd /path/to/directory/
  ls -t | head -n1</code></pre>
  
  <p>This sorts it right, and returns the first filename. However, it also seems to includes a line break, which I do not want. As for 2: I can output the text "newest file: " with a different action in the app, and paste the filename behind that. But I'm wondering if you can't return "random text" + the outcome of the <code>ls</code> command.</p>
  
  <p>So my question is: can I do this only using the <code>ls</code> command? And how do I get <em>just</em> the name of the latest file without any linebreaks or returns?</p>