Topic: Dynamic places (pipe menu)

This script generates a menu similar to #!'s default Places menu but it isn't static, so there's no need to update it all the time if you rearrange your home directory structure a lot. By default it displays any directory in ~/ or /media

To use the menu save the script somewhere, let's say ~/.config/openbox/places.py and then make it executable ("chmod a+x ~/.config/openbox/places.py" in a terminal). Then add a line like this to your openbox menu.xml file:        

<menu execute="~/.config/openbox/places.py" id="dynamic_places" label="Places"/>

If you'd like the script to be useable system wide, then save it somewhere like /usr/bin instead of ~/.config/openbox and change the paths used in my examples to match. Thanks greenmanspirit and omns for this explanation, hope you don't mind me using it here where it's easy to find.

Look here for more information on pipe menus: http://icculus.org/openbox/index.php/He … Pipe_menus

Important variables if you want to customise the generated menu:
manager - File manager which you want to use (nautilus, thunar, pcmanfm, rox-filer, konqueror, dolphin, etc).
dirs - The script lists and displays the subdirectories of these directories
ignore - Any item exactly matching an entry in this list will not be displayed
items - If you want to add a single directory entry to the menu you can do it here

Any suggestions on how to improve this would be appreciated.


Update:

* Removed trailing / characters from menu entries as suggested by Foomandoonian.

* The expanduser() function is now only called once, so that if you want to you can hardcode your home dir in its place and remove the "from os.path import expanduser" line. Doing this will make the script less portable, but should make it a tiny bit faster.

* The ignore list now accepts wildcards for pattern matching.
    * - Matches everything
    ? - Matches any single character
    [seq] - Matches any character in seq
    [!seq] - Matches any character not in seq

* Added a variable for file manager, makes it easier to change if you don't use Thunar. Thanks for the idea kestrel.

* List of directories is now alphabetical. Thanks kestrel, can't believe I didn't think of this. It's currently set to preserve the order of directories you set in the dirs variable. Read the script comments if you want to change this.

Thanks for putting this in the pastebin corenominal. I'll try and keep these links current.

View the script here
The direct download link is: http://crunchbanglinux.org/pastebin/?dl=195

Last edited by kev (2009-02-26 02:37:47)

Re: Dynamic places (pipe menu)

This is pretty nice, only thing I could suggest would be pattern matching but you already have that in your comments. Other than that, it seems to do all it needs to.

Re: Dynamic places (pipe menu)

Agreed, it is a very nice pipemenu and fast too! Nice work. cool

I would be interested to know if anyone thinks this should be included by default, in place of the current static menu?

Re: Dynamic places (pipe menu)

I hope you (Kev) do not mind, but I have copied your script to the pastebin for easy download.
The direct download link is: http://crunchbanglinux.org/pastebin/?dl=33

Re: Dynamic places (pipe menu)

corenominal wrote:

I would be interested to know if anyone thinks this should be included by default

+1 smile  This works well and is a better option than the current static setup.

Re: Dynamic places (pipe menu)

corenominal wrote:

I would be interested to know if anyone thinks this should be included by default, in place of the current static menu?

+1

Last edited by greenmanspirit (2008-12-20 18:21:31)

Re: Dynamic places (pipe menu)

I have to ask the noobish question: do I just paste this into the menu XML? hmm

foomandoonian's tumblelog & twitter

Re: Dynamic places (pipe menu)

what i did was save the script in .config/openbox as places.py and then replaced the places section in menu.xml with this line <menu id="places" label="Places" execute="~/.config/openbox/places.py"/>

restart openbox and you should be good to go

Re: Dynamic places (pipe menu)

^ I did pretty much the same thing but saved it in /usr/bin as 'dplaces' so that it would be available system wide. My menu.xml entry looks like this -  <menu id="dynamic_places" label="Places" execute="dplaces"/>

Re: Dynamic places (pipe menu)

I like the look of greenmanspirit's method, but sadly it just doesn't work for me. I just get a small, blank submenu.

I'd try omns method, but I don't have permissions for that directory. hmm

foomandoonian's tumblelog & twitter

Re: Dynamic places (pipe menu)

Foomandoonian wrote:

I like the look of greenmanspirit's method, but sadly it just doesn't work for me. I just get a small, blank submenu.

Make sure the file is executable. You can do this in thunar by right clicking on the file and choosing Properties->Permissions Tab, then check 'Allow this file to run as a program'

Re: Dynamic places (pipe menu)

Thanks omns. I did that, but it didn't fix it, so I decided to copy the code from the first post, and this time it worked perfectly. Originally I used the code from the pastebin, so either there is an error in there or (more likely) my cut and paste skills need work!

One small suggestion: It'd be nice to remove the trailing slash from each item. I think this would look tidier.

Great stuff. Thx. cool

foomandoonian's tumblelog & twitter

Re: Dynamic places (pipe menu)

I knew i forgot to say something, sorry i left out the permissions thing.

Re: Dynamic places (pipe menu)

Foomandoonian wrote:

Originally I used the code from the pastebin, so either there is an error in there or (more likely) my cut and paste skills need work!

You need to use the download link in the pastebin rather than copying and pasting. This would have caused the error.

Re: Dynamic places (pipe menu)

+1 Cool and quick. Replaced places.

Now if we could get it to do sub-sub-directories in a sort of drill down method.

My web activities: Twitter | Identi.ca | Facebook | Blog

Re: Dynamic places (pipe menu)

I was actually playing around with that, I could get it to show all subdirs, but i couldn't click on anything since the action of the menu is to show its subdirs, if there is a way to make a menu option have two actions then it would probably work. That is two actions as in open on click, show subdirs on hover.

Last edited by greenmanspirit (2008-12-20 23:11:01)

Re: Dynamic places (pipe menu)

greenmanspirit :: Look at how Philip setup obmenu to handle the "Preferences" menu and the "OpenBox Config" menu. Maybe there would be a hint there?

My web activities: Twitter | Identi.ca | Facebook | Blog

Re: Dynamic places (pipe menu)

Ah, i can do something like that but it would mean double entries, one entry to show subdirs and the other to click to open. I'm trying to think if there is a way to have one entry but both actions.

This is all assuming that kev doesn't mind me hacking away at his script.

19

Re: Dynamic places (pipe menu)

Thanks for the responses everyone. I've made two small changes to the script, and updated the first post to include new download links and a quick guide (courtesy of omns and greenmanspirit) to using this in your openbox menu.

Sub-sub directories would be nice. So would pattern matching for ignored items. I'll see what I can think up, and if anyone else can think of a good way to do it then hack away.

Re: Dynamic places (pipe menu)

Foomandoonian wrote:

Thanks omns. I did that, but it didn't fix it, so I decided to copy the code from the first post, and this time it worked perfectly. Originally I used the code from the pastebin, so either there is an error in there or (more likely) my cut and paste skills need work!

Actually, I think there maybe an issue with the pastebin. I am not sure at the moment if the issue only affects Python, needs further investigation, but the download file offered by the pastebin is DOS formatted, doh! This can be fixed by running this command:

cat 40.txt | tr -d '\r' >40.txt.fixed

Where 40.txt is the downloaded file containing the source. Sorry for the inconvenience, I will try and get this fixed.

Update: I am pretty sure I have now fixed this. I think it is a fair assumption that the majority of people using the pastebin are going to be using Linux, so I have created a filter to remove all DOS style end of line carriage returns. Hopefully this should solve the issue. hmm

Re: Dynamic places (pipe menu)

@corenominal: just get it with pastebin, no problem at all, seem like you solve the issue smile
@kev: very good script, thanks for sharing wink

+1 for add this script by default

arpbook is dead - arpinux is born, and became a deviant.

Re: Dynamic places (pipe menu)

omns wrote:
Foomandoonian wrote:

I like the look of greenmanspirit's method, but sadly it just doesn't work for me. I just get a small, blank submenu.

Make sure the file is executable. You can do this in thunar by right clicking on the file and choosing Properties->Permissions Tab, then check 'Allow this file to run as a program'

Same errors for me I'm afraid... sad

My artwork at deviantART   |    My Tweet   | My upcoming web page
Nulla dies sine GIMP!
ASUS Eee PC 1000 HE | 2GB | 120GB OCZ Vertex 2 SSD | #! Statler

Re: Dynamic places (pipe menu)

Kev, great job. I just noticed you updates to places.py. Thanks. Is it possible to get the menu to sort alphabetically?

Also for those of us using PCMan we can change line 54

    print 'thunar ' + i

to

    print 'pcmanfm ' + i

Maybe this could be handled with a variable at the head of the script.

My web activities: Twitter | Identi.ca | Facebook | Blog

Re: Dynamic places (pipe menu)

Hello all,

Is this script still available?  I've tried both links but received errors.  Pastebin entry 33 is not available and Pastebin entry 41 is not available.  Did I miss something?

Thanks!

Re: Dynamic places (pipe menu)

cmccullough wrote:

Hello all,

Is this script still available?  I've tried both links but received errors.  Pastebin entry 33 is not available and Pastebin entry 41 is not available.  Did I miss something?

Thanks!

What he said.