Passing Command Line Arguments to Shortcut from Clipboard

I am just trying to work out how to pass command line arguments from a shortcut to a python script, but I’m hitting an issue when the argument I want to pass is in the clipboard.

The python script is simply

import sys

print(f"Arguments of the script : {sys.argv[1]}")

This works perfectly well.

But this gives the file location of the contents of the clipboard, rather than the clipboard itself.

Any idea how to fix this?

I put this script…

#!/usr/bin/env python3

import sys

print("Arguments of the script: ", str(sys.argv))

… in this location …


… and I set the executable bit…

chmod +x /Users/stephen/scripts/python/

I put “some text” on the clipboard, and ran this shortcut.

I got the following result.

Hope that helps.

1 Like

Yes that does, thank you very much, sharing the shortcut was also very helpful.

I didn’t know that you could insert a variable or the clipboard into the run shell script command, by right-clicking on it, so that was good to learn.

I’ve pruned it down to the bare essentials if anyone else wants to pass the contents of the clipboard to a python script.

The key change was making the python script executable, but I’m not quite sure why! However it does now work which is great, thanks again for your help.