You are not logged in.

Announcement

Due to heavy spamming of forums registration is going in stages. If you wish to register as a new user with ArchBang Forums, first register and then send an e-mail to: archbangforums at gmail dot com. It should contain the problem you want to discuss or some other AB related content. You will be promoted from registering member with no posting rights to new member with posting rights after that. If your mail is ignored you haven't fulfilled the requirements.

#1 2012-05-26 21:07:34

matt0076
New member
Registered: 2012-05-26
Posts: 8

Openbox Menu Customization [Solved]

Hey, archbang community. I'm trying to change my openbox menu "places" to be based around "/home/matt/Directory" instead of "/home/matt". This seemed like an easy thing to fix , but i've opened my obpipemenu-places and tried editing it but found myself lost.

Here's my [the default] obpipemenu-places code, which I believe is what I should be changing.

#!/usr/bin/perl
# Recursively browse filesystem through openbox3 pipe menus
#### Usage: add
# <menu id="browse" label="Browse" execute="obpipemenu-places ~" />
# to your .config/openbox/menu.xml
#### CAVEAT ####
# This script was hacked on exclusively in stints between the hours of
# 4 and 5 in the morning. Quality may have suffered.
####
# Script by dircha from ob list on 05/17/04
# suggested improvements by John Russell on 05/17/04 implemented 
# a year later by Kacper Wysocki.
# 05/30/05 - Kacper Wysocki
# - opens files with 'rox', which launches appropriate file handler
# - hidden directories now stay hidden
# - spaces, ampersands in dir- and filenames are escaped
# - newlines at each entry to make output a little readable
# 06/04/05 - Kacper Wysocki
# - use $0 for scriptname
# - use $ENV{'HOME'} as default path
# - now follows symlinks

use strict;

# Command to lauch files with
my $cmd = "pcmanfm";

my $path = $ARGV[0];
$path = $ENV{'HOME'} if $path eq "";
my @files = split /\n/, `ls -1p '$path'`;
mk_menu_element($path, @files);

sub mk_menu_element {
    my ($path, @files) = @_;

    print "<openbox_pipe_menu>\n";
    
    # "Browse here..." lauches this dir
    print "<item label=\"Browse here..\">".
           "\n\t<action name=\"Execute\">".
           "\n\t\t<execute>$cmd '$path'</execute>".
           "\n\t</action>".
           "\n</item>\n".
           "<separator />";

    foreach $_ (@files) {
        my $length = length $_;
        my $last_c = substr $_, $length - 1, 1;

        if ($last_c eq "/") {
            print mk_dir_element($path, substr $_, 0, $length - 1);
        } elsif ($last_c eq "@") {
            print mk_sym_element($path, substr $_, 0, $length - 1);
        } else {
            print mk_file_element($path, $_);
        }
    }
    print "</openbox_pipe_menu>\n";
}

sub mk_dir_element {
    my ($path, $name) = @_;
    # escape ampersand and space in pathnames
    $path =~ s/&/&amp;/g;
    $name =~ s/&/&amp;/g;
    $path =~ s/ /\\ /g;
    $name =~ s/ /\\ /g;

    return "<menu id=\"$path/$name\" label=\"$name\" execute=\"$0 $path/$name\" />\n";
}

sub mk_sym_element {
    my ($path, $name) = @_;
    # escape ampersand in pathnames
    $path =~ s/&/&amp;/g;
    $name =~ s/&/&amp;/g;

    # Follow symlinks instead of opening links in rox.
    return "<menu id=\"$path/$name\" label=\"$name\" execute=\"$0 $path/$name\" />\n";
=cut
    return "<item label=\"$name\">".
           "\n\t<action name=\"Execute\">".
           "\n\t\t<execute>$cmd '$path/$name'</execute>".
           "\n\t</action>"
           . "\n</item>\n";
=cut
}

sub mk_file_element {
    my ($path, $name) = @_;
    my $label = $name;
    # escape ampersand in pathnames
    $path =~ s/&/&amp;/g;
    $name =~ s/&/&amp;/g;

    return "<item label=\"$name\">".
           "\n\t<action name=\"Execute\">".
           "\n\t\t<execute>$cmd '$path/$name'</execute>".
           "\n\t</action>"
           . "\n</item>\n";
}

If someone could help, a thousand internets to you smile

Last edited by matt0076 (2012-05-26 21:08:09)

Offline

#2 2012-05-26 22:13:14

fschiff
Member
Registered: 2011-04-04
Posts: 29

Re: Openbox Menu Customization [Solved]

Use code tags!

These are the important lines:

my $path = $ARGV[0];
$path = $ENV{'HOME'} if $path eq "";


$ARGV[0] is the parameter passed on the command line.  If its blank, use your home directory (the environment variable).

So, all you have to do is pass the directory you want in the call to obpipemenu-places in the open box menus.

Offline

#3 2012-05-26 22:28:48

matt0076
New member
Registered: 2012-05-26
Posts: 8

Re: Openbox Menu Customization [Solved]

fschiff wrote:

Use code tags!

These are the important lines:

my $path = $ARGV[0];
$path = $ENV{'HOME'} if $path eq "";


$ARGV[0] is the parameter passed on the command line.  If its blank, use your home directory (the environment variable).

So, all you have to do is pass the directory you want in the call to obpipemenu-places in the open box menus.

I'm not quote sure what a parameter passed on the command line means honestly, I've tried substituting the #ARG[0] for #ARG[/home/matt/Directory], as well as {'HOME'} for {'/home/matt/Directory'} but neither worked. What exactly did you mean?

Offline

#4 2012-05-26 23:43:00

Mr Green
Iso Developer
Registered: 2010-11-07
Posts: 3,746

Re: Openbox Menu Customization [Solved]

Why not try

$path = "$ENV{'HOME'}/<directory>" if $path eq "";

Change <directory> to whatever you need

Offline

#5 2012-05-27 00:50:38

matt0076
New member
Registered: 2012-05-26
Posts: 8

Re: Openbox Menu Customization [Solved]

Mr Green wrote:

Why not try

$path = "$ENV{'HOME'}/<directory>" if $path eq "";

Change <directory> to whatever you need

didn't change a thing unfortunately, i tried like a hundred times

edit: I changed <directory> to /home/matt/Directory just confirming this is what you meant

Last edited by matt0076 (2012-05-27 00:51:18)

Offline

#6 2012-05-27 01:23:21

Mr Green
Iso Developer
Registered: 2010-11-07
Posts: 3,746

Re: Openbox Menu Customization [Solved]

Read it again

$path = "$ENV{'HOME'}/Directory" if $path eq "";

Am assuming you are running

$ENV{'HOME'}/home/user/directory

Offline

#7 2012-05-27 02:15:10

matt0076
New member
Registered: 2012-05-26
Posts: 8

Re: Openbox Menu Customization [Solved]

#!/usr/bin/perl
# Recursively browse filesystem through openbox3 pipe menus
#### Usage: add
# <menu id="browse" label="Browse" execute="obpipemenu-places ~" />
# to your .config/openbox/menu.xml
#### CAVEAT ####
# This script was hacked on exclusively in stints between the hours of
# 4 and 5 in the morning. Quality may have suffered.
####
# Script by dircha from ob list on 05/17/04
# suggested improvements by John Russell on 05/17/04 implemented 
# a year later by Kacper Wysocki.
# 05/30/05 - Kacper Wysocki
# - opens files with 'rox', which launches appropriate file handler
# - hidden directories now stay hidden
# - spaces, ampersands in dir- and filenames are escaped
# - newlines at each entry to make output a little readable
# 06/04/05 - Kacper Wysocki
# - use $0 for scriptname
# - use $ENV{'HOME'}/home/matt/directory as default path
# - now follows symlinks

use strict;

# Command to lauch files with
my $cmd = "pcmanfm";

my $path = $ARGV[0];
$path = "$ENV{'HOME'}/Directory" if $path eq "";
my @files = split /\n/, `ls -1p '$path'`;
mk_menu_element($path, @files);

sub mk_menu_element {
    my ($path, @files) = @_;

    print "<openbox_pipe_menu>\n";
    
    # "Browse here..." lauches this dir
    print "<item label=\"Browse here..\">".
           "\n\t<action name=\"Execute\">".
           "\n\t\t<execute>$cmd '$path'</execute>".
           "\n\t</action>".
           "\n</item>\n".
           "<separator />";

    foreach $_ (@files) {
        my $length = length $_;
        my $last_c = substr $_, $length - 1, 1;

        if ($last_c eq "/") {
            print mk_dir_element($path, substr $_, 0, $length - 1);
        } elsif ($last_c eq "@") {
            print mk_sym_element($path, substr $_, 0, $length - 1);
        } else {
            print mk_file_element($path, $_);
        }
    }
    print "</openbox_pipe_menu>\n";
}

sub mk_dir_element {
    my ($path, $name) = @_;
    # escape ampersand and space in pathnames
    $path =~ s/&/&amp;/g;
    $name =~ s/&/&amp;/g;
    $path =~ s/ /\\ /g;
    $name =~ s/ /\\ /g;

    return "<menu id=\"$path/$name\" label=\"$name\" execute=\"$0 $path/$name\" />\n";
}

sub mk_sym_element {
    my ($path, $name) = @_;
    # escape ampersand in pathnames
    $path =~ s/&/&amp;/g;
    $name =~ s/&/&amp;/g;

    # Follow symlinks instead of opening links in rox.
    return "<menu id=\"$path/$name\" label=\"$name\" execute=\"$0 $path/$name\" />\n";
=cut
    return "<item label=\"$name\">".
           "\n\t<action name=\"Execute\">".
           "\n\t\t<execute>$cmd '$path/$name'</execute>".
           "\n\t</action>"
           . "\n</item>\n";
=cut
}

sub mk_file_element {
    my ($path, $name) = @_;
    my $label = $name;
    # escape ampersand in pathnames
    $path =~ s/&/&amp;/g;
    $name =~ s/&/&amp;/g;

    return "<item label=\"$name\">".
           "\n\t<action name=\"Execute\">".
           "\n\t\t<execute>$cmd '$path/$name'</execute>".
           "\n\t</action>"
           . "\n</item>\n";
}

is what I have (which still isn't working), what did you mean by that last part?
oh, and thank you so much for your patience!

Last edited by matt0076 (2012-05-27 02:17:26)

Offline

#8 2012-05-27 02:32:33

Mr Green
Iso Developer
Registered: 2010-11-07
Posts: 3,746

Re: Openbox Menu Customization [Solved]

You have edited the wrong line

It is the path line that needs to change

This is wrong

$ENV{'HOME'}/home/matt/directory 

It must read like this

$ENV{'HOME'}/directory 

Assuming that directory is in /home/matt change to where ever you need it

Offline

#9 2012-05-27 05:58:29

fschiff
Member
Registered: 2011-04-04
Posts: 29

Re: Openbox Menu Customization [Solved]

You should be editing your menu.xml file.
Easiest to mess with.
Honestly!  The pipe menu tells you the usage in the 4th line.

Offline

#10 2012-05-27 10:06:45

matt0076
New member
Registered: 2012-05-26
Posts: 8

Re: Openbox Menu Customization [Solved]

Mr Green wrote:

You have edited the wrong line

It is the path line that needs to change

This is wrong

$ENV{'HOME'}/home/matt/directory 

It must read like this

$ENV{'HOME'}/directory 

Assuming that directory is in /home/matt change to where ever you need it

are you talking about changing

my $path = $ARGV[0];

to

 my $path = $ENV{'HOME'}/directory 

? because the line after that already reads

$path = "$ENV{'HOME'}/Directory" if $path eq "";

and none of this is doing anything.

And yea, "directory" is in /home/matt.



fschiff wrote:

You should be editing your menu.xml file.
Easiest to mess with.
Honestly!  The pipe menu tells you the usage in the 4th line.

I tried playing around with it, but the menu.xml just runs pipemenu so it's not much use unless I want to rewrite the whole pipemenu

Offline

#11 2012-05-27 10:11:25

darktux
Member
From: Lisbon, Portugal
Registered: 2011-11-10
Posts: 42

Re: Openbox Menu Customization [Solved]

I tried a simple way and it worked for me:

1. Execute obmenu
2. Find the pipe menu of 'Palces'
3. In  the box 'Execute', the last 'command' is '~/'
4. Change it to the disired folder, for exemple '~/Documents'


Fluent in Portuguese and Bad English

Offline

#12 2012-05-27 10:14:24

Mr Green
Iso Developer
Registered: 2010-11-07
Posts: 3,746

Re: Openbox Menu Customization [Solved]

Even easier wink

Offline

#13 2012-05-27 10:17:14

matt0076
New member
Registered: 2012-05-26
Posts: 8

Re: Openbox Menu Customization [Solved]

darktux wrote:

I tried a simple way and it worked for me:

1. Execute obmenu
2. Find the pipe menu of 'Palces'
3. In  the box 'Execute', the last 'command' is '~/'
4. Change it to the disired folder, for exemple '~/Documents'

oh my god it worked I was trying that when I first started but it wouldn't let me edit it. Thank you so much. Also thank you Mr Green for sticking with me for so long!

Offline

#14 2012-05-27 12:31:56

Mr Green
Iso Developer
Registered: 2010-11-07
Posts: 3,746

Re: Openbox Menu Customization [Solved]

Thanks goes to darktux for an even simpler answer..... have marked thread as solved

Welcome to ArchBang

Offline

Board footer

Powered by FluxBB