title: How to get name of frontmost app with AppleScript and use it to get the filepath
body: <p><strong>What I try to do:</strong></p>
  
  <p>When I'm in one of my text editors (TextEdit, Byword, FoldingText) I want this AppleScript to display the file path.</p>
  
  <p>I figured asking for the frontmost window app get's me the apps name nice and easily and then I can ask for the POSIX path in the next step.</p>
  
  <p><strong>The Problem:</strong></p>
  
  <p>The script is already 99% there, but I'm missing something. When I try to use the variable of <code>activeApp</code> it doesn't work and I get this error:</p>
  
  <pre><code>Error Number:System Events got an error: Can’t get application {"TextEdit"}.
  -1728
  </code></pre>
  
  <p>Here's the script:</p>
  
  <pre><code>tell application "System Events"
       set activeApp to name of application processes whose frontmost is true
  
       --This doesn't work either:
       --do shell script "php -r 'echo urldecode(\"" &amp; activeApp &amp; "\");'"
  
       tell application activeApp
           set myPath to POSIX path of (get file of front document)
       end tell
       display dialog myPath
  end tell
  </code></pre>
  
  <p>If I exchange <code>activeApp</code> with <code>"TextEdit"</code> everything works. Help would be appreciated.</p>
  
  <p><em>Maybe there's something in here that helps: <a href="https://stackoverflow.com/questions/6930323/get-process-name-from-application-name-and-vice-versa-using-applescript">Get process name from application name and vice versa, using Applescript</a></em></p>