0

EDIT 9: Before writing an answer saying to change Exec=/home/insertUsernameHere/volumeGUI/volumeGUI.py to Exec=something or another, the .desktop file Exec= code isn't the problem as it runs fine with gtk-launch. The problem is that it doesn't run from Show Applications, it just does nothing. Also please watch my screen capture so you can see exactly what the problem is.

I’ve been trying (for a couple of hours now) to get a .desktop file to run my python script, but when I click on the icon in the applications window, nothing happens.

Here’s my .desktop code:

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Exec=/home/insertUsernameHere/volumeGUI/volumeGUI.py
Name=Volume GUI
Icon=/home/insertUsernameHere/volumeGUI/volumeGUI_Logo.png

Note that when I run /home/insertUsernameHere/volumeGUI/volumeGUI.py in the terminal it works fine.

EDIT: Here's my python code

#!/usr/bin/env python3

from tkinter import *
from tkinter.font import *
import subprocess

top = Tk()
top.resizable(False, False)
top.title("Python Volume Controller")
padx = 10
pady = 10
myFont = Font(family = "helvetica", size = 16, weight = "bold")

volumeTextVariable = StringVar()
currentVolumeText = Label(top, textvariable = volumeTextVariable, font = myFont)
currentVolumeText.grid(row = 1, column = 0, columnspan = 2, padx=padx, pady=pady)

volumeIncrement = 2

def volumeUp(volume):
    if (volume + volumeIncrement) <= 100:
        subprocess.call("pactl set-sink-volume 0 +" + str(volumeIncrement) + r"%", shell=True)
        volumeTextVariable.set("Current Volume: " + getVolume() + r"%")

def volumeDown(volume):
    if (volume - volumeIncrement) >= 0:
        subprocess.call("pactl set-sink-volume 0 -" + str(volumeIncrement) + r"%", shell=True)
        volumeTextVariable.set("Current Volume: " + getVolume() + r"%")

def getVolume():
    try:
        volume = subprocess.Popen("amixer get Master |grep % |awk '{print $4}'|sed 's/[^0-9]//g'", stdout=subprocess.PIPE, shell=True).communicate()[0].decode("utf-8")[:-1]
    except:
        volume = -404
    return volume

volumeTextVariable.set("Current Volume: " + getVolume() + r"%")

volUpButton = Button(top, text = "Volume Up", command = lambda: volumeUp(int(getVolume())), font = myFont)
volDownButton = Button(top, text = "Volume Down", command = lambda: volumeDown(int(getVolume())), font = myFont)
volUpButton.grid(row = 2, column = 1, padx=padx, pady=pady)
volDownButton.grid(row = 2, column = 0, padx=padx, pady=pady)

top.mainloop()

EDIT 6: GIF of me running the .desktop file in the command line with gtk-launch volumeGUI.desktop and it working, but not working when trying to launch it from Show Applications
Screen Capture

EDIT 7: I have since improved my python code: https://paste.ubuntu.com/p/QF6PVrSPSy/

EDIT 8: I changed Exec=/home/insertUsernameHere/volumeGUI/volumeGUI.py to Exec=bash -c "/home/insertUsernameHere/volumeGUI/volumeGUI.py 2>&1 > ~/logfile.txt" as per a suggestion and when I either run it with gtk-launch or try and run it from Show Applications the log file is empty.

5
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – terdon
    Aug 28, 2018 at 13:32
  • No idea what has been written in the meantime, but works instantly here. So we have a few options: 1. paths are incorrect (try paste the icon path in e.g. firefox, see if it shows) 2. script is not executable (needs to be if you don't call the interpreter) 3. If you use the .desktop file from your desktop, it needs to be executabel and trusted. Can't think of anything else. Encoding isn't needed btw, deprecated if I remember well. Sep 3, 2018 at 13:20
  • @JacobVlijm If you look in the chat you'll see I'm able to run the .desktop file with gtk-launch in the command line as per a suggestion but I'm still unable to launch it by clicking on it in either Show Applications, the bar down the left of the screen, or Files. Sep 3, 2018 at 15:08
  • @SgtOddball No clue what gtk-launch exactly does, but could you please confirm/double check the paths match exactly, paste the icon path in a browser. Just to make sure, but you are aware you need to double-click on the icon if it is on your desktop, to show it in the launcher, it needs to be in ~/.local/share/applications, right? As said, it works instantly here. Sep 3, 2018 at 18:43
  • @JacobVlijm it's in ~/.local/share/applications and I can see it in Show Applications, if you watch the screen capture GIF in edit 6 you'll see exactly what happens. edit: I don't know what gtk-launch does either, it was suggested in the comments that have since been moved to a chat. Sep 3, 2018 at 19:01

1 Answer 1

1

Try changing Exec=/script.py to Exec=python3 /script.py

I have several Java programs that I run via .desktop files. Some even get executed on boot... Sorry so short, posting via my phone.

5
  • I am able to run the .desktop file with gtk-launch, the code in the .desktop file works. Sep 3, 2018 at 15:38
  • 1
    The only other thing is executable permissions for the .desktop file... Like I said, I have several of these that I use regularly. I can execute all of them with several methods... I tried! Lol
    – BillWeckel
    Sep 3, 2018 at 15:42
  • A screenshot of the files permissions: imgur.com/a/MvOZZUp Sep 3, 2018 at 16:00
  • Sorry, Bill, this has been tried before. There's whole discussion in the chat and comments, and 3 deleted answers that mentioned this. Sep 3, 2018 at 18:55
  • I tried this and works for some py scripts.
    – WesternGun
    Jul 29, 2021 at 13:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .