Xfce Forum

Sub domains
 

You are not logged in.

#1 2019-01-13 08:33:00

nachbar
Member
Registered: 2019-01-13
Posts: 6

Execute .py script from Whisker menu

Hi all,

I have a Python program that launches just fine, when I double-click on the .py file within Thunar. Also executing it from the terminal with

'python myfile.py '

works. Does anybody have an idea why it wouldn't work as a launcher from Whisker menu? I put in:

python /home/nachbar/Folder1/Folder2/myfile.py

It just won't start. I also tried

/usr/bin/python /home/nachbar/Folder1/Folder2/myfile.py

But nothing happens when trying to launch. sad

Offline

#2 2019-01-13 09:34:42

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 818

Re: Execute .py script from Whisker menu

what do you do in the whisker menu to launch?  does it show up there?  what's in its .desktop file?

Offline

#3 2019-01-13 10:04:03

nachbar
Member
Registered: 2019-01-13
Posts: 6

Re: Execute .py script from Whisker menu

The .desktop file looks like this:

[Desktop Entry]
Version=1.1
Type=Application
Name=myfile
Comment=blabla
Icon=applications-other
Exec=python /home/nachbar/Folder1/Folder2/myfile.py
Actions=
Categories=Other;X-XFCE;X-Xfce-Toplevel;


It's located in .local/share/applications/menulibre-myfile.desktop

Offline

#4 2019-01-23 08:09:56

sh4tr
Member
Registered: 2014-03-20
Posts: 32

Re: Execute .py script from Whisker menu

whisker menu is a freedesktop compliant launcher

have ~/.local/bin/
put your script there
chmod +x your.py

Exec=your.py

Offline

#5 2019-01-24 20:39:35

nachbar
Member
Registered: 2019-01-13
Posts: 6

Re: Execute .py script from Whisker menu

Thanks for the suggestion.

So I moved the py script to /home/nachbar/.local/bin.

In there I did a 'chmod +x myfile.py'

I then changed the Exec in the .desktop file to =myfile.py

Unfortunately it still does nothing.

Offline

#6 2019-01-25 04:33:54

sh4tr
Member
Registered: 2014-03-20
Posts: 32

Re: Execute .py script from Whisker menu

Offline

#7 2019-01-25 05:43:47

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 818

Re: Execute .py script from Whisker menu

i'm curious if you are able to get it to run from the desktop ... a .desktop file in ~/Desktop.  my python3 scripts work from there.

Offline

#8 2019-01-26 00:06:56

mint4all
Member
From: off the map
Registered: 2018-08-21
Posts: 265

Re: Execute .py script from Whisker menu

nachbar wrote:

Thanks for the suggestion.
So I moved the py script to /home/nachbar/.local/bin.
In there I did a 'chmod +x myfile.py'
I then changed the Exec in the .desktop file to =myfile.py
Unfortunately it still does nothing.

Greetings!

Not being a pythonati myself, i did some sleuthing. Linux Mint (my distro of choice) uses a whole bunch of bash scripts to launch "mint-y" stuff, such as its "Welcome" splash. Here's the welcome script:

#!/usr/bin/python3

import os

os.system("/usr/lib/linuxmint/mintwelcome/mintwelcome.py")

Simply typing "welcome" in a terminal will display that screen. Then using whisker's app search bar, i had it place a launcher on the desktop. That one works like a charm too (after allowing the launchr to launch). Then i created my own launcher on the panel -- same result. It just works. If you model your shell script accordingly based on Mint's design (modified to reflect your program's paths) it should "just work" ...

Cheers, m4a


Linux Mint 21.2 -- xfce 4.18 ... Apple iMAC -- Dell & HP Desktops and Laptops -- Family & Community Support

Offline

#9 2019-01-26 00:37:30

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 818

Re: Execute .py script from Whisker menu

remember, i'm still relatively new to Xfce.  i have switched all but one of the userids on my laptop over to it.  i hope to switch that last one as soon as i can.

i have learned quite a few things about Xfce but not everything, yet.  for example, i now know how to have a script set up a launcher to run another script on the desktop space or as the result of a captured keystroke.  but i don't yet know how to do that on the panel or i menus such as Whiskers' dropdown menu.  everywhere that i have set up a script, i have done it either in bash or in python3, mostly the latter.  i am sure that all recent Linux distros have both.  i believe recent BSDs do, as well.

i'd like to know what to do to set up activation from the panel or various menus.  while i do want to know how to do it from a script, i might be able to figure it out for a script by knowing the manual means.  this is usually a matter of doing a few manual set ups and seeing what changes happen to the files.

i hope to eventually be a contributor to the Xfce community.

Offline

#10 2019-01-26 00:52:24

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 818

Re: Execute .py script from Whisker menu

something i hope to create soon is a plugin on the panel that supports switching to other users quickly and smoothly.  the way i imagin this plugin working is to allow configuring a few users to show up on the panel for a quick switch by just clicking on their name or icon, or dropping down the first menu of all users that are currently logged in.  then a means to go to a side menu with all the remaining users.

i'm  thinking of trying out some desktop switchers tonight.

i wish that when a script get run via a.desktop file or something like it, that i passes alone the file path to where that file is located.  that would simplify many things by letting the script see all the details of the context they are run under.

i'm hoping to offer some python2 and python3 examples to help encourage the use of python.

Offline

#11 2019-01-26 00:57:52

mint4all
Member
From: off the map
Registered: 2018-08-21
Posts: 265

Re: Execute .py script from Whisker menu

Skaperen wrote:

... i'd like to know what to do to set up activation from the panel or various menus.  while i do want to know how to do it from a script, i might be able to figure it out for a script by knowing the manual means.  this is usually a matter of doing a few manual set ups and seeing what changes happen to the files.

i hope to eventually be a contributor to the Xfce community.

Just like yourself, i'm here to learn. I firmly believe that xfce is one of the finest -- if not THE finest -- all-around DEs. Its code is clean, tight, predictable, and has not left me in a lurch for the past 4+ years since my dysmal windoz days sad ... I too hope that at some point i'll be able to put shoulder to grindstone and be of some help here.

Now, to your question. Have a look at "[man] gtk-launch" which i understand is the glue between executables, scripts, launchers (.desktop files) and xfce's interfaces. A 2nd helper app to look into would be "autokey" which hooks into the x-server's keyboard handling and fakes resulting keyboard [output] streams. That might just do what you want; idk. I've used it on occasion to automate repetitive tasks, and it works quite well.

Cheers, m4a


Linux Mint 21.2 -- xfce 4.18 ... Apple iMAC -- Dell & HP Desktops and Laptops -- Family & Community Support

Offline

#12 2019-01-26 03:18:56

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 818

Re: Execute .py script from Whisker menu

right now, the important tool for me is the one to do user switching.  this is for a combination of reasons.  i work with up to about 10 or so userids concurrently logged in.  i do this for various forms of context isolation.  i started doing this before applications, such as Firefox, implemented their weaker forms of isolation ... profiles.  this practice works better in so many ways.  when i first wanted to switch to Xfce, i thought i would have to implement this tool before i could seriously be using Xfce.  when i switch 2 users over, i discovered that the Unity plugin that did user switching was somehow inherited and works (other things it does do not work).  so i went ahead and switched over all but one userid which is the userid that runs my setup scripts that get confused by Xfce (so the need some redesign).  when that is done, then i can get rid of Unity entirely ... purging its packages.  the user switching that Xfce comes with is awkward to use for the frequent, and sometime rapid, ways i switch around.

Offline

#13 2019-01-26 19:07:52

nachbar
Member
Registered: 2019-01-13
Posts: 6

Re: Execute .py script from Whisker menu

I forgot to mention that I'm using Arch Antergos. Does that make a difference? I don't really understand this stuff.

Offline

#14 2019-02-26 00:41:18

ampersun
Member
Registered: 2015-05-14
Posts: 3

Re: Execute .py script from Whisker menu

To run a python (.py) file and have the menu item show up in the Whisker Menu:

Open "menulibre"

(or the default menu editor of your choice")

(in my case... the "win" key shortcut opens Whisker Menu)

In the "Search Window", type Menu (either "Menu Editor", "Main Menu" options show in Whisker menu "apps column")

Choose whatever option you have, mine is "Menu Editor" ( which in my case is menulibre. if you do not have menulibre then you may want to install that through your Package Manger. In my case that is Synaptic, or from terminal "sudo apt-get install menulibre").

My Example python (.py) file is for Zeegaree (which is a timer/stopwatch program)

MENULIBRE:

Left column of menulibre, choose the category you want to use by left clicking on the category item (in my case I choose Accessories). The right panel now changes to show the category you selected.

At the top left you should see a Green "+" icon. Left click that "+" icon and choose "Add Launcher" from the popup window. Right panel now changes to show the launcher pane.

Where it says "New Launcher" left click to highlight this area and then type the name you wish to use and press <enter> (in my case I type "Zeegaree").

Where it says "A small descriptive blurb about this application." type your blurb and press <enter> (in my case "A timer and stop watch for your desktop").

The icon box next to these two items, left click, choose"Browse Icons" or "Browse files" (if you have a specific icon you want to use, then search for the icon you want to use in the popup window), (in my case I choose "Browse files" then search for my icon and select that from the popup window in the search and choose the icon that I have saved in "/home/sexierthanmost/Documents"), then select "Apply" at the bottom to get back to the "launcher pane" in menulibre.

Once back in the "launcher pane", under "Application Details" where it says "Command" Type <python "/path/to/your/python/file.py"> without the <> symbols (make sure you include the quotation marks as shown in the command example though, and then press <enter> (in my case the command is .... python "/home/sexierthanmost/Programs/Zeegaree-master/zeegaree.py").

At the top of the menulibre window choose the "Save Icon"

After saving using the "Save icon" close "menulibre".

Open whisker menu in your usual way and just start typing the name you used in the "New Launcher" field that you entered in menulibre (In my case I type "zeegaree"). There in the Whisker menu you should see your newly created launcher with your chosen icon and chosen New Launcher name and a descriptive blurb.

Left click or just hit <enter> if your program is highlighted. (In my case i see The "Zeegaree Icon" I saved in Documents, "Zeegaree", "A timer and stop watch for your desktop." Zeegaree is selected and so I just hit <enter> and Zeegaree starts!

No desktop file to mess with! Easy-peasy, and sexier-than-most!

Enjoy!

Offline

Board footer

Powered by FluxBB