title: Python script won't run on keyboard shortcut
body: <p>So i have plenty of scripts which i run from keyboard shortcuts, things like uploading screenshots to imgur and putting links in the clipboard, stuff for digitising plots, etc.</p>
  
  <p>I have this current script, which only runs from the terminal, and not when i try to run it as a keyboard shortcut.</p>
  
  <p>I'm trying to run it via the <code>System &gt; Preferences &gt; Keyboard Shortcuts</code> on <code>Scientific linux 6.4</code>.</p>
  
  <p>I've included the script below, in case there's anything specific about it which would stop it from working.</p>
  
  <pre class="lang-py prettyprint-override"><code>#!/usr/bin/python
  import fileinput, os
  
  import subprocess
  
  from pygments import highlight
  from pygments.lexers import get_lexer_by_name, guess_lexer
  import pygments.formatters as formatters
  
  #stdin = "\n".join([line for line in fileinput.input()])
  
  p = subprocess.Popen(["xclip", "-selection", "primary", "-o"], stdout=subprocess.PIPE)
  code, err = p.communicate()
  
  if not err:
  
    lexer = guess_lexer(code)
  
    print lexer.name
  
    imageformatter = formatters.ImageFormatter(linenos=True, cssclass="source", font_name="Liberation Mono")
    formatter = formatters.HtmlFormatter(linenos=True, cssclass="source")
  
    HTMLresult = highlight(code, lexer, formatter)
    Jpgresult = highlight(code, lexer, imageformatter, outfile=open("syntax.png", "w"))
  
    with open("syntax.html", "w") as f:
  
      f.write("&lt;html&gt;&lt;head&gt;&lt;style media='screen' type='text/css'&gt;")
      f.write(formatters.HtmlFormatter().get_style_defs('.source'))
      f.write("&lt;/style&gt;&lt;/head&gt;&lt;body&gt;")
      f.write(HTMLresult)
      f.write("&lt;/body&gt;&lt;/html&gt;")
  
  
  #  os.system("pdflatex syntax.tex")
  
    os.system("firefox syntax.html")
  
    os.system("uploadImage.sh syntax.png")
  
  
  
  else:
    print err
  </code></pre>
  
  <p>The way it works, is by extracting the clipboard selection using <code>xclip</code>, using <code>pygments</code> on the text, and then both creating an html document and opening it in firefox, and uploading an image to imgur (using another script i have, which i know 100% works), and then putting that image url back into the clipboard.</p>
  
  <p>The <code>bin</code> folder it resides in is in my path.</p>
  
  <p>I've tried all of:</p>
  
  <pre><code>script
  script.sh (where this file is just a shell script which calls the python script)
  /home/will/bin/script
  /home/will/bin/script.sh
  </code></pre>
  
  <p>as the <code>command</code> in the <code>keyboard preferences</code>.</p>
  
  <p>If i change the contents of these scripts to just something like <code>notify-send "hello"</code>, and that then produces the notification message, so i'm fairlyconfident it's a probelm with the script, and not the <code>keyboard shortcuts</code> menu.</p>