[Solved]How to set a python script as default program in Linux Mint 20 Cinnamon?

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
z593118
Level 1
Level 1
Posts: 10
Joined: Wed Sep 28, 2022 10:58 am

[Solved]How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by z593118 »

Could somebody provide clear short guidelines (steps) how to set a python script as default to open file (jpg) when I double click on it. Tried to understand a similar post but it is not clear to me. I have picviewer.py and would like to open file pic.jpg located on /home/pics. Please help
Last edited by LockBot on Tue Mar 28, 2023 10:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Samu369
Level 1
Level 1
Posts: 1
Joined: Tue Sep 27, 2022 10:58 am

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by Samu369 »

In your python script type these two lines of code:

Code: Select all

import os
os.system("/home/pics/pic.jpg")
if you can't run your script open the terminal in the folder where the .py file is contained (by right clicking in the folder and then open terminal) and then type:

Code: Select all

python3 picviewer.py
z593118
Level 1
Level 1
Posts: 10
Joined: Wed Sep 28, 2022 10:58 am

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by z593118 »

Thanks for reply, but may be I was not clear enough: my question was not about double clicking on my script, but on any pic in some directory. I need guidelines how to add my script to the list of available default programs to open pics. Thanks
z593118
Level 1
Level 1
Posts: 10
Joined: Wed Sep 28, 2022 10:58 am

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by z593118 »

May be it is not really beginner's question :wink:
mikeflan
Level 16
Level 16
Posts: 6969
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by mikeflan »

Maybe we should back up and see what is so special about the python script. What does it do to the jpg file?
Can we just put the jpg files in a specific directory and tell the python script to run on all the jpg files in that directory?
User avatar
Dhela Frank
Level 1
Level 1
Posts: 30
Joined: Sun Sep 12, 2021 5:16 pm
Location: Uyo, Nigeria
Contact:

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by Dhela Frank »

z593118 wrote: Wed Sep 28, 2022 1:44 pm Thanks for reply, but may be I was not clear enough: my question was not about double clicking on my script, but on any pic in some directory. I need guidelines how to add my script to the list of available default programs to open pics. Thanks
what does the script do?
Linux is only Free, if your time has no Value
»Zawinski's

Image

~Flutter Dev
z593118
Level 1
Level 1
Posts: 10
Joined: Wed Sep 28, 2022 10:58 am

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by z593118 »

The script is a picture viewer, and it works fine for opening files when I start the program itself (picture viewer). However, I would like to start it by double clicking on pic file, i.e., want it as default program to open jpg files.
mikeflan
Level 16
Level 16
Posts: 6969
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by mikeflan »

A very reasonable request. Sorry I don't know how to do that.
twerq
Level 3
Level 3
Posts: 111
Joined: Sun Jul 05, 2020 10:55 am

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by twerq »

z593118 wrote: Thu Sep 29, 2022 1:50 pm The script is a picture viewer, and it works fine for opening files when I start the program itself (picture viewer). However, I would like to start it by double clicking on pic file, i.e., want it as default program to open jpg files.
So you are about to make Cinnamon think your script is Application. Then you can check jpg file Properties -> Open With tab and set your script as a default application
AFAIK you should create (copy) the desktop file for your needs. Just look though /usr/share/applications/. There are plenty of them. Place your edited copy to ~/.local/share/applications/ and it should workout
mikeflan
Level 16
Level 16
Posts: 6969
Joined: Sun Apr 26, 2020 9:28 am
Location: Houston, TX

Re: How to set a python script as default program in Linux Mint 20 Cinnamon?

Post by mikeflan »

I guess if we are going to keep both of these posts we should create a link to the other post:
viewtopic.php?f=47&t=382702
Locked

Return to “Beginner Questions”