IDLE (Python 3.4) - Execute a script on launch
<p>I've been spending the last week or so creating a simple touch friendly GUI in python3.4 (on the raspberry pi). Now I setup python to run my script on launch, but I ran into the problem, that I couldn't open other programs from within my program (such as the web browser or calculator). However if I use IDLE to execute the script and not the standard python program in the terminal, opening other programs from my scrip works! I already created a .sh file that runs when the Linux Gui starts, which opens up my script in IDLE, however it only opens the file and doesn't execute it.</p>

<p>So now here is my question: Can I create a .sh script, which opens IDLE and runs a python script in the IDLE console (I already tried the exec command when launching idle with no results)</p>

<p>Right now this is my command, which should execute the loaded file, but only loads it for some reaseon:</p>

<pre><code>sudo idle3 -c exec(open('/path/to/my/file.py').read())
</code></pre>

<p>Any help is appreciated :)</p>

<h3>Use Idle's cli options</h3>

<p>You have a few options, of which the best one is to use the <code>-r</code> option. From <code>man idle</code>:</p>

<pre><code>   -r file
          Run script from file.
</code></pre>

<p>This will however only open the <em>interpreter</em> window. Since you also want the editor, this will do pretty much exactly what you describe:</p>

<pre><code>idle3 '/path.to/file.py'  &amp; idle3 -r '/path.to/file.py'
</code></pre>

<p>The <em>startup</em> command you need is then:</p>

<pre><code>/bin/bash -c "idle3 '/path/to/file.py'  &amp; idle3 -r '/path/to/file.py'"
</code></pre>

<p><a href="http://i.stack.imgur.com/iD0c9.png" rel="nofollow"><img src="http://i.stack.imgur.com/iD0c9.png" alt="![enter image description here"></a></p>

<p>The command you tried will not work, since <a href="https://linux.die.net/man/2/idle" rel="nofollow">here</a>, we can read:</p>

<blockquote>
  <p>Only process 0 may call idle(). Any user process, even a process with superuser permission, will receive EPERM. </p>
</blockquote>

<p>Therefore, we depend on cli options of <code>idle</code>, which luckily provide an option :)</p>

<hr>

<h3>Alternatively</h3>

<p>Another option would be to open the file with <code>idle3</code> wait for the window to appear and simulate <kbd>F5</kbd>:</p>

<pre class="lang-sh prettyprint-override"><code>/bin/bash -c "idle3 '/path/to/file.py'  &amp; sleep 3 &amp;&amp; xdotool key F5"
</code></pre>

<p>This would need <a href="https://www.freebsd.org/cgi/man.cgi?query=xdotool&amp;apropos=0&amp;sektion=1&amp;manpath=FreeBSD%208.1-RELEASE%20and%20Ports&amp;format=html" rel="nofollow">xdotool</a> to be installed on your system.</p>

<p>An advanced version of this wrapper would open the file with <code>idle</code>, subsequently check if the new window exists, is focussed and simulate <kbd>F5</kbd> with <code>xdotool</code>. </p>

<p>These would however be the dirty options, which we luckily don't need :).</p>

python linux shell raspberry-pi python-idle