#!/usr/bin/env python3

# Hey, this is the script of your new action.

# It's easy to create an action.

# - Get selected text from `stdin`
# - Write result to `stdout`
# - Write errors to `stderr`
# - Exit with non-zero exit code to prevent applying on error
# - Get parameters from command line arguments

# Here is example:

from sys import stdin, stdout, stderr, argv

# Read from stdin...
input_string = stdin.read()

# ...parse parameters...

integer_arg = int(argv[1])
string_arg = argv[2]
float_arg = float(argv[3])

# Booleans are represented by empty (false) and non-empty (true) strings,
# so you can cast them to `bool` directly.
boolean_arg = bool(argv[4])

# ...process string...
output_string = 'You said "' + input_string + '"'

# IMPORTANT: trailing newline isn't ignored, so you shouldn't
# print it if you don't really want it to be in result string.

# ...handle errors...
if len(output_string) > 30:
    stderr.write('The message is too long')
    exit(1)

# ...and write result to stdout
stdout.write(output_string)

# Even if you use Text Pieces in Flatpak,
# this script is ran outside the sandbox,
# so here you can use anything that is available
# on your host system.

# You can use any language, not only Python.
# Just replace interpreter path in the first line with. 
#
# For more information see: https://en.wikipedia.org/wiki/Shebang_(Unix)

# Compiled languages are not supported, but
# if you *really* want, you can put any
# binary to this script location
