Simple Pekwm Categorized Menu Populator (Shell Script)

I wanted to share this script I wrote in the hope that it will prove to be as convenient to some of you as it has been to me.
Suggestions and modifications are welcome.
#! /bin/sh
#USING WITH PEKWM
# -Install this file to ~/.pekwm/scripts/menugen.sh
# -Add this line to ~/.pekwm/start:
# ~/.pekwm/scripts/menugen.sh > ~/.pekwm/dynamic
# -Add this line where desired to the RootMenu section of ~/.pekwm/menu:
# INCLUDE = "dynamic"
# -Reload Pekwm
# -Restart Pekwm
#This will allow the menu to regenerate each time Pekwm restarts.
#MAKING ADJUSTMENTS
#Select a list of categories into which you would like your applications to be sorted, then add them to the "CATS=..." line below separated by spaces.
#Some common values are:
# CATEGORY DESCRIPTION
# AudioVideo Application for presenting, creating, or processing multimedia (audio/video)
# Audio An audio application Desktop entry must include AudioVideo as well
# Video A video application Desktop entry must include AudioVideo as well
# Development An application for development
# Education Educational software
# Game A game
# Graphics Application for viewing, creating, or processing graphics
# Network Network application such as a web browser
# Office An office type application
# Science Scientific software
# Settings Settings applications Entries may appear in a separate menu or as part of a "Control Center"
# System System application, "System Tools" such as say a log viewer or network monitor
# Utility Small utility application, "Accessories"
#For a better idea of how your applications may be categorized, you may also want to inspect the contents of the "Categories=" line of the various *.desktop files under /usr/share/desktop/
CATS="Audio Graphics Network Settings System Utility"
for CAT in $CATS; do
echo " Submenu = \"$CAT\" {"
for CATMATCH in `grep -l "^Categories=.*$CAT.*" /usr/share/applications/*.desktop`; do
name=`sed -n '1,/^Name=/ s/^Name=//p' <$CATMATCH`
exec=`sed -n '1,/^Exec=/ s/^Exec=//p' <$CATMATCH`
echo " Entry = \"$name\" { Actions = \"Exec ${exec% %[UuFf]}\" }"
done
echo " }"
done

No matter how you chose to do it it's going to be a bit more work than a simple shell script. There are a lot of choices though.
Objective-C/Cocoa (this is how most of the big boys do it)
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCTutorial/01Introdu ction/chapter1_section1.html
AppleScript Studio
http://developer.apple.com/documentation/applescript/conceptual/studiobuildingap ps/chapter01/chapter1_section1.html
Python/Cocoa bridge
http://developer.apple.com/cocoa/pyobjc.html
There are more options if none of these appeal to you.
Eric

Similar Messages

  • Can I run a shell script from the Services menu?

    This would be kind of cool.
    Is there a simple way to do this?

    Doesn't look like there is a direct way to do it.
    The services are all Bundles, which is easy
    enough to fake -- just copy one from /Library/Services
    to ~/Services and modify the plist. Put your shell
    script in Contents/MacOS/ and identify it in the
    plist under CFBundleExecutable and hope for the
    best
    Where it gets sticky is CFBundlePackageType (APPL
    for Application, FMWK for FrameWork, BNDL for
    'loadable bundle', whatever that is] and NSServices.
    CFBundlePackageType should pose no problem if Services
    use the OS loader and handles file magic [and '#!' of
    course].
    NSServices specifies a named port that the app
    listens on, the data type it receives, and so forth.
    This looks a bit harder to fake. I'd bet Applescript
    has the functionality, and there may be some
    command-line hooks to backend that, or it may be
    possible to netcat your way through it.
    But it doesn't look trivial
    Property List Key Reference
    Anyways, tried it with a quick script that echoes to a
    file, and haven't figured out how to refresh the
    Services menu to get it to appear. Probably have
    to NetInfo it or something ridiculous; doesn't appear
    to watch the FS.
    [ Edited by Apple Discussions Moderator; href URL ]

  • I can't get a simple "do shell script" in AppleScript to work!

    Hi All,
    I can get simple commands like "do shell script "ls"" or "do shell script "ps"" to work in AppleScript, but I cannot get something like "do shell script "python -V"" to work. (yes, my shell script says: do shell script "python -V" (no double quotes!))
    This is driving me nuts!
    Can anyone help?
    - Jon

    python -V appears to direct its output to stderr. Try
    do shell script "python -V 2>&1"

  • Simple shell script utility to copy abs tree for build

    Hi,
        I'm learning shell script and decided to make a simple script to copy the folder i want from /var/abs to
        a new folder so i can build the package. here it is: (remember, i'm new to shell scripting, if you know a better way to do it, you can modify my script
        and post here a better solution, so, i (and others) can learn with my errors)
    #!/bin/bash
    #Looks for the abs tree of the software you want
    #and copy it to your build path
    ABSTREE=/var/abs
    echo -n "What software do you want? "
    read absname
    result=$(find $ABSTREE -name $absname)
    for i in $result; do
    echo -n "$i, is this what you want? [y/n] "
    read opt
    if [ $opt = "y" ]; then
    echo -n "Copy to... "
    read buildpath
    relative=${i#$ABSTREE}
    absolute=$buildpath${relative%$absname}
    mkdir -p $absolute
    cp -r $i $absolute
    echo "$i successfully copied to $absolute"
    exit 0
    fi
    done
    exit 1

    spoonman wrote: mkdir -p $absolute
    cp -r $i $absolute
    echo "$i successfully copied to $absolute"
    You are assuming `mkdir` and `cp` were successful. You should test them to make sure, and exit with failure if not:
    mkdir -p $absolute || exit 1
    cp -r $i $absolute || exit 1
    echo "$i successfully copied to $absolute"
    You could also include your own error message, but mkdir and cp would throw their own if something fails...
    mkdir -p $absolute || { echo "mkdir failed"; exit 1; }
    cp -r $i $absolute || { echo "cp failed"; exit 1; }
    echo "$i successfully copied to $absolute"
    Another way is to use `set -e` which will exit the script on any failure without explicit testing:
    set -e
    mkdir -p $absolute
    cp -r $i $absolute
    set +e
    echo "$i successfully copied to $absolute"

  • Can I run a shell script from the services menu?, part II

    Remember this?
    It is now possible.

    Doesn't look like there is a direct way to do it.
    The services are all Bundles, which is easy
    enough to fake -- just copy one from /Library/Services
    to ~/Services and modify the plist. Put your shell
    script in Contents/MacOS/ and identify it in the
    plist under CFBundleExecutable and hope for the
    best
    Where it gets sticky is CFBundlePackageType (APPL
    for Application, FMWK for FrameWork, BNDL for
    'loadable bundle', whatever that is] and NSServices.
    CFBundlePackageType should pose no problem if Services
    use the OS loader and handles file magic [and '#!' of
    course].
    NSServices specifies a named port that the app
    listens on, the data type it receives, and so forth.
    This looks a bit harder to fake. I'd bet Applescript
    has the functionality, and there may be some
    command-line hooks to backend that, or it may be
    possible to netcat your way through it.
    But it doesn't look trivial
    Property List Key Reference
    Anyways, tried it with a quick script that echoes to a
    file, and haven't figured out how to refresh the
    Services menu to get it to appear. Probably have
    to NetInfo it or something ridiculous; doesn't appear
    to watch the FS.
    [ Edited by Apple Discussions Moderator; href URL ]

  • Running a simple shell script

    Not being a regular user of terminal on OSX, I have managed to forget how to run a simple shell script. The purpose of the script is to rename a set of files contained in a specific directory. Here is a sample of the script I wrote some time back:
    mv product_22.jpg 080688614423.jpg
    This command repeats for each file I need to rename. My recollection is that I simply put the actual script text file in the same directory as the images to be renamed and drag the script file into a new terminal window and hit enter to run. When I try this however I receive the following error:
    ord2: Permission denied
    Can anyone help me out here? I'm running 10.2.8. I seem to beforgetting a critical step somewhere along the way.
    Thanks
      Mac OS X (10.2.x)  

    Have you set the execution bit for the script? When not, use: chmod 755 script.

  • Simple Shell Script Question.... [java related]

    Hey guys! This is my first post, as im new here :S
    I have a simple problem for a big program.
    We have a .sh to install it, but when I run the .sh in terminal like i should, It says the class is not found. I believe it has to do with the syntax, as the person who made it is not a linux pro. I don't know MUCH about shell scripts, but I'm pretty sure I know where the error lies.
    Our Script:
    java -classpath ./:./jars/tools.jar:./jars/nexus.jar impsoft.nexus.installer.Install
    chmod a+x run.sh compile.sh
    The Error:
    Exception in thread "main" java.lang.NoClassDefFoundError: impsoft/nexus/installer/Install
    What I think the problem is:
    ./jars/nexus.jar impsoft.nexus.installer.Install
    Thank you for ALL of your help!

    Hi Justin,
    Have you tried running the lines from the command line?
    The second thing you may want to try is changing the relative directory for the jar file from a relative one to a fixed directory. From the error, it appears that the install program is running but it is not able to locate a library mentioned in the program (which is probably the jar file listed in the classpath).
    Hope that helps.
    J. Haynes
    Denver

  • Creating simple shell script packages to deploy with ARD and TaskServer

    I am looking for a simple step by step on how to create a package that can be deployed using ARD, to run a simple shell script like
    "softwareupdate -i -a"
    A brief search here returned nothing, but perhaps I was not using the correct terms.
    Ultimately, I want to use ARD to run software update on ~400 Macs.
    Thanks in advance for your help.
    Bill

    If I send it as a unix command, it will run only on machines that are currently awake and responding to ARD.
    If I can set it up as a package, then I can use Task Server to "deploy" the command to machines that are not currently online. When the machines next contact the Task Server, they will be told to run softwareupdate.

  • I am trying to use automator to make a simple app that when I open it, it comes up with a dialog box that asks for a link that you want to download. and it will download it for you using the curl -O shell script in Terminal. How would I do it?

    I want this so I can just download anything I want by just having the link and I have made a few things with shell scripts in automator before, just never anything where i need to input a value into the shell script.

    Easy:

  • Simple shell script issue

    Hi,
    I have an issue with following shell script:
    #!/bin/sh
    env | while read VAR; do
    RIGA=$RIGA"\""$VAR"\";"
    done
    echo $VAR
    echo $RIGA
    exit 0
    Why the last echo commands (echo $VAR and echo $RIGA) don't give me any result? Why $VAR and $RIGA are empty?

    From what I understand, anything to the right of a pipe is run in a sub-process in non POSIX shells, which runs in it's own environment. Variables changed inside ta sub-shell are not changed at the parent process.
    Perhaps using ksh instead of bourne shell will work, or you could try input redirection rather than using pipe command. e.g.:
    while read VAR; do
    RIGA=$RIGA"\""$VAR"\";"
    done < $(env)
    echo $VAR
    echo $RIGA
    exit 0
    Edited by: Dude on Dec 15, 2010 6:11 AM

  • How to use the result of simple shell script?

    The shell script below retrieves the length of an audio file:
    set aFile to choose file
    do shell script "afinfo " & quoted form of (POSIX path of aFile) & "|grep duration"
    I'm wondering, how can I copy the result to the clipboard or set the value of a variable to it?
    Total newbie question. I have no idea about shell scripts - I just found the script above online.
    Thank you so much!

    Here:
    set the clipboard to (do shell script "afinfo " & quoted form of (POSIX path of aFile) & "|grep duration")
    or:
    set A to do shell script "afinfo " & quoted form of (POSIX path of aFile) & "|grep duration"
    (53997)

  • Simple shell script problem...

    I am trying to get a list of directories on a remote machine, compare them with the directories on the local machine and copy any that dont match on the local machine to a backup folder. Heres my code but i am a newbie and i cant get my shell script to read from a file. The for loop never executes so i am guessing i am not reading the file correctly - see below.
    #!/bin/ksh
    ssh -l removeserver 192.168.xxx.xxx ls /remote/server/directory/ > /store/remote/directory/listing/motapp1files.txt
    newfile=''
    $newfile < /store/remote/directory/listing/motapp1files.txt
    for file in $newfile;
    do echo $file
    if [ ! -d local/machine/directories/$file/ ]; then
    echo "this folder doesnt exist on on remote server "; echo $file;
    fi
    done

    Re-inventing the wheel perhaps. Look into rsync. Great program!
    I used it in FreeBSD to do a very similar task.

  • Ways to run a shell script that starts a python script

    I have a shell script that is used to launch a python (2.5.1 installed via Fink) script (IDLE). The shell script, the IDLE script, and the python binary are all in /sw/bin as usual. This all has to be done AFTER X11 has been launched. I have to make this easy for my students to use.
    In each account's home .xinitrc file, I have the lines
    source .profile
    vpython2.5 *
    and this works, but it calls the vpython2.5 script every time X11 is launched. I've tried adding the vpython2.5 command to the X11 Applications menu, but this works ONLY if I add /sw/bin to the script name. Apparently the menu doesn't "know" about the current PATH setting. The keyboard shortcut I put in the menu neither shows up nor works either. So much for that option.
    Now I've discovered Platypus and it looked promising, but I'm obiously not using it correctly and from the documentation, I can't figure out what I'm doing wrong.
    So here's the ultimate question. Is there a way to use Platypus to encapsulate the vpython2.5 script, preferably also starting up X11, so students will only have to click on the new app's icon? This is how OpenOffice.org starts up. It seemed simple enough to do in Platypus, but I never saw the IDLE window open up.

    I added a shortcut key "j" for the "xman" app in X11, and it seems to work fine. Did you press the command key with the shortcut key? Are you sure the shortcut key you selected does not overlap with others in the menubar?
    There should be no problems creating an application with Platypus using a shell script. In my experience, you have to source all necessary files, assuming that the shell script does not recognize your terminal settings. You can also launch X11.app in the shell script with the following command:
    command open -a X11
    It is a good idea to pause the shell script until X11 finishes launching. To do this, you need a command like,
    command sleep 5
    Otherwise, if you try to start X11-dependent apps in the shell script while X11 is launching, it will fail. There may be better ways to do this.
    Hope this helps.

  • Shell Script GUI

    Hi, I'm very new to OS X development. I have three shell scripts that I'd like to add a GUI to, just a simple dropdown menu that can select which script you want to run, then run that script by clicking an "Okay" button, or something of the sort. Right now I have it running with an automator .app that runs the shell script, but I'd like to add a simple GUi. Any help would be much appreciate =)

    No matter how you chose to do it it's going to be a bit more work than a simple shell script. There are a lot of choices though.
    Objective-C/Cocoa (this is how most of the big boys do it)
    http://developer.apple.com/documentation/Cocoa/Conceptual/ObjCTutorial/01Introdu ction/chapter1_section1.html
    AppleScript Studio
    http://developer.apple.com/documentation/applescript/conceptual/studiobuildingap ps/chapter01/chapter1_section1.html
    Python/Cocoa bridge
    http://developer.apple.com/cocoa/pyobjc.html
    There are more options if none of these appeal to you.
    Eric

  • LoginHook Shell Script not running?

    I have a very simple login shell script (open http://pathtowebsite.local) that I have set as a LoginHook. When running the script from the Terminal, it opens the website, as expected. However, on login it appears that something happens, the menu bar flashes and disappears until you click on something, but the website doesn't open. The permissions are set properly, and it is executable. The script is located in the global /Library folder in a folder I created called Management, though I also tried putting it in the /Users/Shared directory in case it was an access issue.
    Any ideas on what I might do to resolve this issue? I can't seem to get it to actually kick off at user login like it should.

    The LoginHook environment is minimum. There is NO PATH
    pwd: /
    id -a: uid=0(root)
    gid=0(wheel)
    egid=80(admin)
    groups=0(wheel),
    1(daemon),
    2(kmem),
    8(procview),
    29(certusers),
    3(sys),
    9(procmod),
    4(tty),
    5(operator),
    80(admin),
    20(staff)
    $1: thelogin_person'susername
    printenv:
    PWD=/
    SHLVL=1
    SECURITYSESSIONID=449a3aa0
    _=/usr/bin/printenv
    Notice, no PATH, no USER environment variables, just about nothing as an environment.
    So there is no way for the LoginHook to find the 'open' command.
    Try changing your script to /usr/bin/open

Maybe you are looking for

  • Download file for Palm/Mac reader is damaged

    First of all, on the download page for the Reader for Palm OS Mac (http://www.adobe.com/products/acrobat/readstep2_mobile.html#palmMac), it says the file is 8.7 MB, but when the file is downloading, it says 9.4 MB, which turns out to be the actual si

  • Is AirPlay Mirroring available for Mac pro?

    Is AirPlay Mirroring available for Mac pro? Need to share my MAC screen with apple TV display and eliminate the cable.

  • Camera RAW/Photoshop still deficient

    These "Do it now" items remain: • Camera RAW still does not have the same crop overlays as both Photoshop and Lightroom (e.g., Golden Spiral, Triangle, etc.) • Photoshop still has a broken Focus Stacker (Edit Menu: Auto Blend: Stack) • Bridge AOM (Ad

  • Blackberry desktop won't accept my password

    hi I finally installed blackberry desktop so that I could upload some music to my 9360.  When I hooked up my phone it asked for my password which I entered only it hasn't accepted it.  I'm now down to my final go and don't really want to end up wipin

  • Adaptive RFC Calls

    Hi everybody, From the tutorial I know how to populate a table from an RFC call by using 'create binding' from the context menu of the table. I want to know how I can output data from a RFC without having an input field and search button. So as soon