7 # This script, made for users of Window Maker (http://windowmaker.org) is to
8 # be used along with KDE (http://www.kde.org).
11 # The default directory, ~/.kde/share/applnk/apps, will contain various
12 # sub-directories such as Development, Editors, Internet, etc. If for some
13 # reason, you wish to use an alternate (parent) directory that contains the
14 # various AppName.kdelnk files, it can be specified on the command line.
16 # The directory, if an alternate is specified, MUST be a parent directory to
17 # any/all sub-directories.
20 # -d <KDE App.kdelnk dir> -f <output menufile> -s yes (print to STDOUT)
22 # Example command with args:
23 # -d ~/.kde/share/applnk -f ~/.kde2wmaker.menu -s yes
25 # When the script is run, it will write out a proper Window Maker "External
26 # Menu" entry, that can be included in the menu. When the External Menu has
27 # been correctly configured, the root menu will display a sub-menu containing
28 # all of the KDE related items found. The script only needs to be run when/if
32 # Installation and Configuration:
34 # 1) If /usr/bin/perl is not the location of the perl binary on your system,
35 # the first line should be changed to reflect upon it's location.
37 # 3) Configure Window Maker's menu by editing ~/GNUstep/Defaults/WMRootMenu
38 # This could be done with any text editor, or by using WPrefs. Insert
39 # the following line (if done with a text editor) into the WMRootMenu file.
40 # ("External Menu", OPEN_MENU, "$HOME/.kde2wmaker.menu"),
41 # If done using WPrefs, simply "Add External Menu" from the drop down menu,
42 # then type: $HOME/.kde2wmaker.menu into the "Menu Path/Directory List"
44 # 4) Some KDE entries, such as "Pine" will require a terminal to execute it.
45 # There is a terminal varable below. You may use any terminal, XTerm is the
46 # default. Any command line options such as: -fg -bg, etc. can be
47 # specified in this variable as well.
50 # Michael Hokenson - logan@dct.com
57 ### The External Menu file, this should NEVER point to the root menu file
58 $menufile = "$ENV{'HOME'}/.kde2wmaker.menu";
60 ### Base directory, location of all the KDE AppName.kdelnk files
61 $basedir = "$ENV{'HOME'}/.kde/share/applnk/apps";
66 ### Print to STDOUT, default is YES, a filename is specified
74 ### Process command line arguments
79 } elsif($last eq "-f") {
84 } elsif($arg =~ /^-/) {
85 if($arg =~ /^-[dfs]$/) {
88 die("Unknown option: $arg\n\nUsage: kde2wmaker.pl\n\t-d <KDE App.kdelnk dir> [-f <output menufile>]\n");
94 ### Make sure we actually exist
97 ### Start some error checking
100 ### See if there is an old menu file. If there is, rename it
103 print "\tFound $menufile, renaming\n\n";
104 rename $menufile, "$menufile.old";
108 ### Read in the directories
109 opendir(KDE
,$basedir);
110 @dirs = readdir(KDE
);
113 ### Make sure there is actually something in $basedir
115 print "ERROR:\n\tNothing found in $basedir\n\n";
119 ### Begin writing the menu
121 open(MENUFILE
,"> $menufile");
124 ### Start the main menu entry
126 print "\t\"KDE Applications\" MENU\n";
128 print MENUFILE
"\t\"KDE Applications\" MENU\n";
131 ### Begin processing the directories
132 foreach $dir(@dirs) {
134 ### Handle each directory unless if its hidden (starts with .)
135 unless($dir =~ /^\./) {
136 ### Print out the sub directories
138 print "\t\t\"$dir\" MENU\n";
140 print MENUFILE
"\t\t\"$dir\" MENU\n";
143 ### Look in each directory and process individual files
144 opendir(SUB
,"$basedir/$dir");
145 @subdirs = readdir(SUB
);
148 ### Process files in each sub directory
149 foreach $sub(@subdirs) {
151 ### Once again, process all files but those that are hidden
152 unless($sub =~ /^\./) {
155 open(SUB
,"$basedir/$dir/$sub");
157 ### Search through the contents of the file
158 while($line = <SUB
>) {
161 if($line =~ /^Name=/) {
166 if($line =~ /^Exec=/) {
170 ### If Terminal=1, then we need to execute a term
171 if($line =~ /^Terminal=1$/) {
172 $pargs = "$term -T \"$pname\" -e $pargs";
178 ### Some error checking on the Name and Exec
181 $pname =~ s/\.kdelnk//;
186 $pargs =~ s/\.kdelnk//;
187 print "WARNING:\n\tNo Exec for $pname, using $pargs\n";
190 ### Begin printing menu items
192 print "\t\t\t\"$pname\" EXEC $pargs\n";
194 print MENUFILE
"\t\t\t\"$pname\" EXEC $pargs\n";
199 ### Print the end of the sub menu
201 print "\t\t\"$dir\" END\n";
203 print MENUFILE
"\t\t\"$dir\" END\n";
208 ### Finish off the main menu entry
210 print "\t\"KDE Applications\" END\n";
212 print MENUFILE
"\t\"KDE Applications\" END\n";
221 print "\n.. Finished. There were errors.\n";
224 # print "\n.. Finished.\n";
230 print "ERROR:\n\t$basedir not found\n\tTry another directory.\n";