Open file with custom extension using a python script in OSX

I created a custom file extension and a python script that enabled me to view the content of this file.

Normally to open the file using the python script I would have to go to the terminal and execute the script:

$ path/script.py file.newext

What I want is instead to be able to double click on the file and run the script giving it the filename I clicked on as argument.

It is possible to achieve this creating an Automator app:

After opening Automator select Application as document type.

 

Screen Shot 2016-08-05 at 16.15.03Add a Run Shell Script block using the list of item on the left column. Set Pass input to as argument

Write the command needed to open the file inside the for loop. Save and quit.

Lastly, go on a file with the extension you want to be opened with the script, right click on it and select Get Info.

Where is written “Open with” select Others and put the path to the Automator script you just saved.

For the setting to be applied to all the files with this extension click on the “Change all” button.