Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found this page when I was trying to make python service. I wanted to share my complete solution to save others a little time and maybe get some feedback from more experienced coders. I used System Preference>Keyboard:Keybindings to set an "Application Sortcut:All Apps" for this service so I can execute the selected text anywhere in the system using command-shift-return. You will notice that any Exceptions will cause the selection to be replaced with the original text. Works with UNDO if you didn't get the result you were after. So far, I like it a lot!</p> <p>Create an automator workflow as a service, service receives selected text in any application, input is entire selection, output replaces selected text</p> <p>Add a run shell script action, shell: /usr/bin/python pass input: as arguments</p> <p>This code goes in the box:</p> <pre><code>import sys #, random try: print eval(' '.join(sys.argv[1:])) except: try: #This is a compound statement using variable assignment code = compile(' '.join(sys.argv[1:]), '&lt;string&gt;', 'exec') exec code except: print ' '.join(sys.argv[1:]) </code></pre> <p>These are a few samples of how I might use this service. Again, this works in Mail, word processors and other apps.</p> <p>Sample 0: Basic Math</p> <pre><code>&gt;&gt;&gt; 42*24*60*60 3628800 </code></pre> <p>Sample 1: Single line, compound statement</p> <pre><code>&gt;&gt;&gt; import random; foo = range(17); random.shuffle(foo); print(foo) [11, 14, 12, 3, 1, 4, 15, 7, 8, 13, 2, 16, 0, 10, 9, 6, 5] </code></pre> <p>Sample 2: Multiline</p> <pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; foo = range(17) &gt;&gt;&gt; random.shuffle(foo) &gt;&gt;&gt; print(foo) [5, 16, 14, 10, 3, 11, 7, 15, 12, 0, 13, 2, 4, 1, 6, 9, 8] </code></pre> <p>Sample 3: Loops</p> <pre><code>&gt;&gt;&gt; for x in range(5): ... print x ... 0 1 2 3 4 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload