Executing and Saving a Python File?

Hi,

I've written a little python script for creating passwords - which i want to run for new passwords.

How do i run it and store it in a variable?

password_generator.py.zip (1.2 KB)

The first thing you will need to know is the full path to the Python interpreter which you want to use,

and the simplest approach might just be to point that to the path of a .py file.

An option on the Execute shell script action will let you copy the output to a named variable

image

In that event, i might have programmed it wrong. Beause currently it does not return anything, if i do what you suggest :sweat_smile:

Are you sure you have the right path to your python interpreter ?

And when you say 'does not return anything', are you looking in the randomPassword variable ?

In Terminal.app, to get a viable path, try one of these commands (depending on whether you want to use Python 2.7 or Python 3, which will need to have been installed by you)

which python

or

which python3

This, for example :

  • using a command substitution to obtain a valid path to a Python interpreter
  • and writing a Python source file (similar to yours) to Desktop from a variable

is working here.

password by python.kmmacros (3.5 KB)

1 Like

Wow this perfectly meets my use case... and is much simpler than what I was trying to do.

Does Save to variable: capture colored terminal output as well?

The Execute a Shell Script action is not a Terminal – it is a script-runner-mechanism – therefore it cannot generate colored text.

For that matter variables are text-only and could not render colored text, even if it was available.

-Chris

Thanks, Chris.

If it helps others, I was able to save this terminal output to a text file and can use the Atom package Language-Ansi-Styles to change it back to color.

1 Like