2

So im trying to create a desktop shortcut for a terminal mp3player i made in python. I'm using Lubuntu.

My program looks like this

#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import random
from sys import stdout

from pygame import mixer # Load the required library


class mp3Player(object):
    def __init__(self):
        self.mix = mixer
        self.mix.init()

    def play(self, filelist):
        for root, mp3file in filelist:
            try:
                stdout.write(root + '\n')
                stdout.write("Playing %s\n"%mp3file)

                self.mix.music.load(os.path.join(root, mp3file))
                self.mix.music.play()

                while self.mix.music.get_busy():
                    choice = raw_input("[skip, exit, pause, shuffle]\n")
                    if choice == "skip":
                        break
                    elif choice == "pause":
                        self.mix.music.pause()
                        raw_input("Press enter to continiue.")
                        self.mix.music.unpause()
                    elif choice == "shuffle":
                        random.shuffle(filelist)
                        break
                    elif choice == "exit":
                        raise KeyboardInterrupt
                    else:
                        pass

            except KeyboardInterrupt, e:
                self.mix.music.stop()
                print("User Interrupted")
                sys.exit(0)

            stdout.flush()

class mp3Files(object):
    def __init__(self):
        self.mp3player = mp3Player()
        self.filelist = []

    def search(self):
        for root, dirs, files in os.walk(os.getcwd()):
            for mp3file in files:
                if mp3file.endswith(".mp3"):
                    self.filelist.append((root, mp3file))

        self.mp3player.play(self.filelist)

def main():
    mp3 = mp3Files()
    mp3.search()

if __name__ == "__main__":
    main()

You will need pygame in order to test it and i would recommend to execute it in your music folder because it searches the current directory recursivly for mp3 files and when it's done it plays the list. However, this is my .desktop file.

[Desktop Entry]
Version=1.0
Name=mp3playa
Comment=Terminal mp3player
Exec=/media/jan/Volume/Musik/mp3playa
TryExec=/media/jan/Volume/Musik/mp3playa
Terminal=true
Categories=Application
Type=Application
GenericName=Simple terminal mp3player

When i double click it, it only opens a terminal without executing the script. What am i doing wrong? oO

Thanks in advance.

Edit:

The file is executable and i executed

 sudo update-desktop-database

and got a warning

Warning in file "/usr/share/applications/gnumeric.desktop": usage of
MIME type "zz-application/zz-winassoc-xls" is discouraged ("zz-
application/zz-winassoc-xls" should be replaced with 
"application/vnd.ms-excel")
3
  • 1
    Have you tried running the "Exec" entry on the command line? In other words: are you sure that your script is actually executable; and that the right thing happens when you try to run it (before turning it into a launcher)?! And just to be sure: you did run "sudo update-desktop-database" after making changes to the launcher; to be sure that any updates are reflected before triggering the launcher after a change?
    – GhostCat
    Commented Mar 30, 2016 at 14:20
  • Yes it is executable from the command line. It's executing if i type ./mp3playa in the terminal. I tried "sudo update-desktop-database" and got a warning in file "/usr/share/applications/gnumeric.desktop": usage of MIME type "zz-application/zz-winassoc-xls" is discouraged ("zz-application/zz-winassoc-xls" should be replaced with "application/vnd.ms-excel"). Does this warning appears because of my .desktop file? :/
    – BigZ
    Commented Mar 30, 2016 at 14:22
  • Well, the warning is pretty clear in pointing to the gnumeric.desktop file; so this most likely has nothing to do with your script.
    – GhostCat
    Commented Mar 31, 2016 at 11:09

1 Answer 1

1

Finally found what i was missing.

Had to start the lxterminal first with the script as command argument.

Exec=lxterminal --command="/home/jan/Schreibtisch/mp3playa/mp3playa"
2
  • As this is actually a python script; you might try "Exec=python /bla/script" as well.
    – GhostCat
    Commented Mar 31, 2016 at 11:10
  • I tried that as well, but it seems Lubuntu's lxterminal explizitly wants the execution command this way.
    – BigZ
    Commented Mar 31, 2016 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.