Sequencing of Python Scripts

I want to run a couple of python scripts in a specific order. The "Pause for ... " contains a safety margin to ensure the script is certainly well completed.

How to run immediately after previous script completed?

I haven't tried this, but the locking and unlocking of a named semaphore might be worth experimenting with:

action:Semaphore Lock [Keyboard Maestro Wiki]


(You might need to split them into 3 distinct macros, all called, in sequence, by a fourth ?)

(Tho FWIW I haven't immediately been able to reproduce any problem of process overlap with a simple sequence of Execute Shell Script actions)

If you use the Execute a Shell Script action to execute your python scripts, this would happen automatically. But you wouldn't see the output like you will running it in the Terminal, plus the environment is different. Normally these are fine, but if you really want to run them in the Terminal for some reason (maybe to see live output for example) then you can use a sentinel of some sort at the end of the execution to tell when it is done.

For example, at the end of each python script, create a new empty file at /tmp/pythondone.txt

In Keyboard Maestro, do:

  • Delete File /tmp/pythondone.txt
  • Execute script as you currently do
  • Pause Until Path condition Something Exists at /tmp/pythondone.txt
  • Delete File /tmp/pythondone.txt

etc…

Alternatively, at the end of the scripts, you could set a Keyboard Maestro variable via Applescript.

4 Likes

Excellent inpsiration, thank you @peternlewis