How to run python script on file with keyboard maestro

I’m pretty sure this is possible but i just havent figured out how. I have a python script that I want to apply to a csv file (a list of jira-tasks and ill filter out relevant tasks for an email). I would love to be able to select the file after downloading it and then run a keyboard maestro on it that triggers a python script that returns a text (a list of the names of certain tasks). Then keyboard maestro would save that in the clipboard so I can paste it in to an email. I have the python code already working with

import pandas as pd
df = pd.read_csv('Jira.csv')[['Summary', "Status", 'Custom field (Growth area)']]
df = df.rename(columns={"Custom field (Growth area)": "Area"})
cleaned = df[((df['Status'] != 'Done') & (df['Status'] != 'Backlog')) & (df['Area'] !='Supply') ]
selectedexp = list(cleaned[cleaned['Status']=='Selected for Development'].Summary)
inprogress = list(cleaned[cleaned['Status']=='In Progress'].Summary)
Awaiting = list(cleaned[cleaned['Status']=='Awaiting results'].Summary)
print("Selected for development:")
for exp in selectedexp: 
for exp in inprogress: 
print("Awaiting results:")
for exp in Awaiting: 

Any hints on how I could get this working with keyboard maestro?

Keyboard Maestro has a For Each Path in Finder Selection that you can use to capture a path into a variable. Then you can reference the Keyboard Maestro variable via the environment module.

Here’s a simple example

Instead of specifying Jira.csv, presumably you would want to include your script in a Keyboard Maestro macro and replace that with a variable’s value of the selected file path.

I think that should work for you.

BTW - as you’re processing CSV - Python has a built in CSV module. I’m curious (and learning) why you chose Pandas. You might well be right; It just seems a bit heavy.

Perfect! Thanks! Works like a charm. In case anyone else wants it for some reason:

Yea, probably overkill but on the other hand I think it is easier to use pandas and well I don’t need those extra milliseconds for this so just went for what is easier for me.