Archive

Posts Tagged ‘command-line’

The mapis Page

September 12th, 2009 subogero Comments off

Ever wondered how difficult it is to send email from a script, if the company you work for is locked into the prison guarded by Windows, Exchange and Outlook?

It’s all right to have a nice script for a software-release process, but what about notifying the interested parties about the release automatically?

Your first shot may be a Visual Basic script. It can create an Outlook email object and write its various fields. There is a small problem though. Outlook is a paranoid little bastard, and asks for your permission for the program to change the email’s fields. And asks it using a dialog-box.

But the casual observer may notice that some programs can pop-up pre-filled Outlook email windows like a breeze. 7-Zip springs to the lips. Right-click something, select `Compress to “foo.7z” and email’, and there pops up the email window with the attachment. No questions asked.

There is actually a very good reason why it’s 7-Zip that springs to the lips. Because it’s FOSS. Free and Open-Source Software. Step forward Igor Pavlov. I don’t want to go into details why, besides being FOSS, 7-Zip is the best archiving program ever, I’d just like to mention the facts that it has a command line interface, an mc-like two-pane GUI, Windows context menu-integration, and the best compression performance.

So I ended up downloading the source, and after a bit of searching I had the solution. Use the interface provided by “mapi.h”. Later I found out that there is a similar program called MAPIsend.exe in the MS BackOffice Resource Kit. A relaxed Hacker might wonder how Redmond invents these names. Anyway, `mapis’ ended up with having nearly identical calling parameters as MAPIsend.

The download package includes sources and the native Win32 binary. Compiled on Linux! Did I mention 7-Zip? It can unpack 7z archives.

Download mapis.7z

Installation:

Save downloaded archive in a new folder called mapis
Unpack archive `7z x  mapis.7z’
Open a cygwin bash window in this folder
Type `make install’
See `man mapis’ or `mapis -h’ for usage

If you don’t have cygwin, get cygwin immediately, but until then just copy the `bin/mapis.exe’  file into a folder which is in PATH, e.g. c:\WINDOWS

Send a simple email to Master Foo, but first check everything in an email window:

mapis -r "Master Foo" -s "The Foo Subject" -m "The Foo message body."

Send another email straight away to Master Foo, copy to the Master Programmer, attach “c:\foo.c” and take the slightly longer message body from file “foomessage.txt”. Oh, and the MCSE shall receive a secret copy, just to scare him with the capabilities of Linux/gcc/mingw32.

mapis -q -r "Master Foo" -c "Master Programmer" -b MCSE \
      -s "foo source" -f c:\foo.c -t foomessage.txt

Yo.

The g Page

August 7th, 2009 subogero Comments off
G’s goal

“g” is a general-purpose command-line launcher for Gnome/Linux, an extended “gnome-open” which can open URLs, files or even programs in a new window. A bit like Windows “start”, just better.

“g” will open a new terminal window.

“g <CLI program>” will open it in a new fully independent terminal window.

“g <GTK+ program>” will open it in a fully independent window.

“g <URL>” will open it with the preferred application.

By an “independent window” I mean two things:

The starting terminal is not blocked while the started app is running;

Closing the starting terminal does not kill the started app.

Bonus: start a Google search for “foo bar” in your preferred browser with

g -g foo bar
Installation:

Download g.tar.gz and extract files in a new directory, preferably “g”.
Type “sudo make” for installation.
Enjoy.

Lessons learned:

How to decide if an argument of a shell-script is a program?

which $1
#prints the location of the command, or nothing if not a command

How to check if a shell-script has no arguments at all?

if [ $# -eq 0 ]

How to check if the last command returned no error in its exit status?

if [ $? -eq 0 ]

The trickiest: how to tell if a command is a terminal- or a GTK+ application?

Search for “libgtk-x11″ in it if it’s a compiled program.
Search for the respective gtk dependency if it’s an interpreter-script:

import gtk # Python
use Gtk2   # Perl

“g” knows these two at the moment, but the list should be extended to all known interpreted languages and graphical toolkits. Actually it should work the other way around, detecting terminal-only applications. But for instance Gimp contains the strings “stdin”, “stdout”, “stderr” and “printf” so I gave up.

I’ve created my first ever very officially looking manual page for “g”, credit goes to Jens Schweikhardt’s very helpful LINUX MAN PAGE HOWTO.

Tao in g

There is more Tao in “g” than in Windows “start”:

Try to start a native Windows program from command line which DOES NOT become fully detached, but blocks your command-line until it closes and returns an exit-status. Hmmm? On Linux, just omit “g”.

On Windows, the commands are scattered around in thousand folders, not listed in the PATH variable. On Linux, on the other hand, all commands are on the PATH, as there are only a few standard places to store them: /bin:/usr/bin:/usr/local/bin. So “g” can access them all.

View the manual page?

man g

Finally, how do you edit the “g” script itself?

g gedit g

ogc – The OG Calculator

July 29th, 2009 subogero Comments off

So my yacc studies led me to a series of thoughts about writing my own command-line calculator with integer arithmetics. Which the Windows Calculator is not.

I set the following goals:

  • 32-bit integer arithmetics (don’t ask me why, I just need it at work, OK?)
  • decimal, octal and hexadecimal formats
  • unlimited undo
  • a fair amount of memory registers
  • ability to continue from the last result (+5 should add 5 to the last result)
  • no mouse clicking
  • following Unix/GNU conventions

The program’s called ogc. I wrote it in yacc surprisingly quickly. The related info and the sources are available on my dedicated ogc page.

Categories: posts Tags: , , ,