Appearance
Running python scripts
Let's zoom out and think about what all this means:
- You can pretty much control ANYTHING on your computer with terminal.
- You can control COMPLETELY control terminal with Pinokio shell.
- This means you can control anything on your computer with pinokio.
To emphasize this concept, let's write a simple python script, which then can be controlled with Pinokio script.
- We will write a python script that takes a string as an argument, and prints a reversed version of it on the terminal.
- Then we will run this python script using Pinokio script.
First create a python file named reverse.py
:
python
import sys
def reverse(input_string):
return input_string[::-1]
print("<pinokio>" + reverse(sys.argv[1]) + "</pinokio>")
This program takes a command line argument, reverses the string, and returns the value wrapped with <pinokio> ... </pinokio>
(Just so it's easier to process the pattern from the Pinokio side.
Now let's write a Pinokio script that runs this python script. Create a file named run.json
in the same folder:
json
{
"run": [{
"method": "shell.start"
}, {
"method": "shell.enter",
"params": {
"message": "python reverse.py helloworld",
"on": [{
"event": "/<pinokio>(.+?)<\/pinokio>/",
"return": "{{event.matches[0][1]}}"
}]
}
}, {
"method": "notify",
"params": {
"html": "{{input}}"
}
}]
}
- It creates a shell session (
shell.start
) - Runs the
python reverse.py helloworld
command (shell.enter
) - Waits for the
/<pinokio>(.+?)</pinokio>/
regular expression event - When it does, it parses the matched part and returns it (
event.matches[0][1]
is the first item in the capture group from the first match) - Then we call the
notify
method to display a push notification with the reversed string