Archive for the ‘Software’ Category

Randomly writing CSV data in PHP

Today’s project: add or replace values in a comma-separated-value file. The application is for tag-counting by week, so the first column is effectively an ID column & the rest (for me) are integers. But here’s the code with some sample data grabbed from a random Google search..

<?
/************** Vars ***************/

$str="id,age,sex,region,income,married,children,car,save_act,current_act,mortgage,pep
ID12101,48,FEMALE,INNER_CITY,17546.0,NO,1,NO,NO,NO,NO,YES
ID12102,40,MALE,TOWN,30085.1,YES,3,YES,NO,YES,YES,NO
ID12103,51,FEMALE,INNER_CITY,16575.4,YES,0,YES,YES,YES,NO,NO
ID12104,23,FEMALE,TOWN,20375.4,YES,3,NO,NO,YES,NO,NO
ID12105,57,FEMALE,RURAL,50576.3,YES,0,NO,YES,NO,NO,NO
ID12106,57,FEMALE,TOWN,37869.6,YES,2,NO,YES,YES,NO,YES
ID12107,22,MALE,RURAL,8877.07,NO,0,NO,NO,YES,NO,YES
ID12108,58,MALE,TOWN,24946.6,YES,0,YES,YES,YES,NO,NO
ID12109,37,FEMALE,SUBURBAN,25304.3,YES,2,YES,NO,NO,NO,NO
ID12110,54,MALE,TOWN,24212.1,YES,2,YES,YES,YES,NO,NO
ID12111,66,FEMALE,TOWN,59803.9,YES,0,NO,YES,YES,NO,NO
ID12112,52,FEMALE,INNER_CITY,26658.8,NO,0,YES,YES,YES,YES,NO
ID12113,44,FEMALE,TOWN,15735.8,YES,1,NO,YES,YES,YES,YES
ID12114,66,FEMALE,TOWN,55204.7,YES,1,YES,YES,YES,YES,YES
ID12115,36,MALE,RURAL,19474.6,YES,0,NO,YES,YES,YES,NO";

$tags2find_arr=array();
$tags2find_arr['ID12106']=array(1=>1,4=>100);  //additive numbers, or replacing?
$tags2find_arr['ID12102']=array(1=>1,4=>200);
$tags2find_arr['ID12114']=array(1=>1,4=>300);

$fn='test.txt';
/************** Runtime ***************/

writeCSV($fn,$str);
writeRandCSV($fn,$tags2find_arr,'add');

/************** Functions ***************/

function writeCSV($fn='',$str=''){

$fh=fopen($fn,'w');
fwrite($fh,$str);
fclose($fh);
}
/****************************/
function writeRandCSV($fn,$tags2find_arr,$addreplace='add'){
$fl=filesize($fn);
$fh=fopen($fn,'r+'); //open for reading, and writing, but don't kill the contents
$str=fread($fh, $fl);

foreach($tags2find_arr as $tag2find=>$csv_data_addreplace){  //$tag2find='ID12108';
//find the line in the str			//alt: explode by '\n' or '\r' &amp;amp; get an array &amp;amp; it's size.. find in array, truncate array,implode &amp;amp; find strlen's for loc &amp;amp; write-len
$readtagloc=strpos($str,$tag2find.',');   //this could be a problem for smaller tags found in larger.. throw a \n before &amp;amp; a , after?
//echo "\r<br/>".$tag2find." @".$readtagloc;

//find it's corollary in the file
fseek($fh,$readtagloc);
$fcsv_arr=fgetcsv($fh); //should only get one line!
//for($i=0;$i<count($fcsv_data);$i++){
//$fcsv_arr[$i]=$fcsv_arr[$i]+$csv_data_addreplace[$i]; //58->59
foreach($csv_data_addreplace as $csv_idx=>$csv_addreplace){
  if($addreplace=='add') $fcsv_arr[$csv_idx]+=$csv_addreplace; //58->59
  else $fcsv_arr[$csv_idx]=$csv_addreplace;
}
//print_r($fcsv_arr);

/******************************/
//echo '\r<br/>'.ftell($fh).' or '.(ftell($fh)-strlen(implode(',',$csv_arr))-1 );
fseek($fh,$readtagloc); //back to beginning of line to write now
//$read=fread($fh, $readlen);
//hoping the pointer is still in the same loc &amp;amp; not @ line-end!

$ok[$tag2find]=fputcsv($fh,$fcsv_arr,',');
$sz=(strlen(implode(',',$fcsv_arr))+1);

//if($ok===false){ echo "FAILURE"; }
//if($ok==$sz){ echo "\r<br/>written length ok:".$ok; }
//else { "\r<br/>written length not ok:".$ok.'<'.$sz; }

} //end foreach tag
$ok[]=fclose($fh);
return $ok;

} //close function
/******************************/
?>

Affective News Feeds

Just last night I found out the glory of Yahoo Pipes. The idea is one for which I’ve wanted & waited a long time: Take *any* web-source & turn it into (through combining, filtering, etc) any other web-source: iCal, RSS, etc.

So the consequence? I now have 3 rss feeds: One for Friend’s Statuses (twitter+facebook), one for news (google news feed) and another for everything else from friends blogs to tech-news.

It would only seem obvious that these 3 can and should be on the same rss reader (I use google reader’s iphone interface, even on my main computer).

The trouble with combining these 3 or 4 types of news into ONE ‘technological ontology’ (a single rss reader) is a simple lessons learned from psychology.. there’s lots of theories like this, but I learned it from Urie Bronfenbrenner, “The Ecology of Human Development.” Basically, we all have various circles, some more core than others, of family, friends, and aquaintences. They affect us differently.

Likewise, we can say data from each source must retain it’s affective priority. Notice how different this is than most News/Social Networking Aggregrates, which merely pull in everything without priority. Likewise, facebook and other marketing groups try to get your affectively involved in their little sphere.

With a little finesse and basic coding-think, yahoo pipes allows me to get each level of data from friends, news & otherwise. Reading them one by one allows me to maintain a relatively consistent affect when reading all 500 tweets, instead of trying to have little affective response to a random news-blip, and then to care deeply over another friends’ status, only to return to not caring. Perhaps that emotional flexibility is possible and desireable in kids, but I’m getting too old for that?

Computers, netbooks & smartphone products table

For all those who were or are now confused about the computer/netbook/smartphone market, here’s a bit to help clear one the techy bits:

Product Hardware Software
Open Microsoft Apple
Computer Intel (x86) Linux (Desktop) Windows OSX
Netbook Intel (x86) Linux (Desktop) Windows hack-only
Netbook (Gen2010) (ARM) Linux (Variants) WinMo
iPad Apple A4 (ARM) iPhone
Phone (ARM) Linux (Variants) WinMo iPhone

Notice that there’s another column I forgot: Android. They’re a variant of Linux, and running on both desktop & netbooks (sort of). Oddly enough, Android on netbooks took all the fire/criticism up front about being too limited. Apple then stepping into the void and filled it with something just. usable. enough.

The only commentary on Apple’s latest device is two-fold: (1) No multitasking? I’m a fan of what I’ve called ‘limited computing‘, but this is a tad too constricting. (2) Likewise constricting is the iPhone AppStore: only those approved by Apple will do.

For the price, I’d rather have AlwaysInnovating’s Tablet/Netbook. It’s effectively the same thing, just with the software I already use. Trouble-spot: all linux software is old-school & menu-driven. Neither linux application communities (KDE nor Gnome) seem to be concerned with this forward motion UI’s.

WordPress Skills (How to hire a WP guy!)

My job just asked me to make a list of what a sister agency should look for in WP ppl. Googling left me with nothing (as all search results seem to have been taken over by SEO ppl lately), so here’s my addition to the mix:

Basic (unquestioned assumptions):
* XHTML syntax, CSS2,
* Browser testing-abilities: IE6-8, FF1-3,Saf3-4, Chrome1-2

WP Basics:
* Upgrading (and fixing when broken!)
* Knowledge of a set of plugins for these common problems:
* “I want a contact form (with these 9 fields)”
* “I want backups”
* “I want a photo gallery (with lightbox)”
* “I want twitter/facebook integration”
* “I want a podcast”
* “I want google maps on my contact page”

WP Intermediate:
* Build/mod a template
* Build/mod a plugin
* jQuery instead of simple, good-ol’-fashioned javascript

Technical/Back-end:
* Can fix ‘broken’ DB’s
* Clean MySQL WP DB from hackers
* phpmyadmin
* MySQL command-line

Users (Teaching skills):
* Guide clients/staff through changing templates, adding special parameters for templates, plugins, upgrades.
* Explain the difference between the 2 editing modes of WP, as well as how a post, page, excerpt are all used.

WP Access controls:
* Should users sign up?
* How to handle editors, admin, readers?
* Public/private posts/pages
* How are comments filtered & what signups required?

SEO:
* What the different HTTP Response numbers mean (#200, 301,302)
* .htaccess mod_rewrite for Apache/Linux servers
* forwarding old sites to WP pages
* forwarding old posts to a archive page
* making ‘pretty urls’ 301 (and why WP default doesn’t do it)
* maing ‘www.’ 301  (and why WP default doesn’t do it)
* The troubles with WP on MS/IIS Servers
* Why XML Sitemaps are good
* Why Google Analytics & Webmaster tools are worth it (and how to interp ‘em to clients)

Anything else out there?

One step closer to useful

UI usability is consistently my no. 1 time-suck. I’ve ‘wasted’ countless hours config’ing and reconfig’ing GNOME panels into assumed-need sorts. I’ve given up and returned to Mac & heeded again the siren call to Linux’ potential simplicity.

My latest spin *was* playing with screen-maximizing UI’s: task-bar-less environments, panel-over-top window-titlebars, then I turned wanna-be tablet with the iPen.

But I’ll not deny, the best ‘inspiration’ has been the non-existent-yet(?) Microsoft Courier. Here’s a list of the bits, related & not, which I’ve come up with:

Dual-pane

My 13″ macbook is nearly-exactly 2×9″ screens. Yes, this is very Courier-esque. Especially if I use Linux’ dragbox in between panes! But the benefit here is window management. In Xwindows-land, there’s lots of these things called ‘window managers’. They’re supposed to, y’know.. manage windows. What do they ACTUALLY do? Place windows in wierd locations & sizes which require you to use a taskbar, alt-tab or expose’ your day away. I’m not down with that. Time for a ’tiling” window manager. Yet I’m just looking for 2 panels, and on a 13″ screen, that’s plenty. If I config my window-placer-thing to throw some of my apps on the left, I (craziest idea ever) can expect them to be there. I know where they are! Which leads me to my next point..

Priority

Since I’m not fussin’ with my 9 windows that are open, wondering where to look for ‘em (something a taskbar is supposed to do, but doesn’t supply the requisite window-parallel usage scenario).. anyways, since I’m not wasting time placing windows, I can focus on what I’m supposed to be doing: being a human with responsibilities over resources and being creative and learning. Those are the categories my applications have taken: email, calendar & files on the left, OpenOffice, Journal & Web on the right.

Lists, lists, lists!

Perhaps this is more iphone-y than anything, but there’s some goodness to be had with the removal of clutter (and there’s plenty on the web!) Yet, I use google calendar & email all day long. I don’t need another cal or mail app, I just need a browser open with these bits in it. But even these apps aren’t clean. Facebook, Yahoo Mail, Google Mail, Google Reader AND Google Calendar ALL have sidebars. Why, oh why do we need sidebars? They take up sooo much screen real-estate, especially after you scroll.

Bad:

What you get when viewing web-apps half-screen'd or in portrait

What you get when viewing web-apps half-screen'd or in portrait

Good:

Ahh, mobile: a clutter-free web-experience!

Ahh, mobile: a clutter-free web-experience!

You just have to load the mobile versions of the webapps you use. To find them, I viewed them on my phone & checked the url. I’ve also found the ‘print’ versions of yahoo news to be similarly readable.

Conditions: sure forcing all my windows into 2 locations (left/right) & 2 states (half-screen or maximized) is ‘limiting’, but I’m a limited human! I need some parallels here to stay sane. I can’t be moving & resizing windows all day long.

Perhaps I’m just getting old, and will eventually regress into the old lady who only has one window open (maximized) at a time. Until then, this is a good compromise.

Courier, please deliver soon, or I’ll make you out of Linux!

Everyone’s all abuzz with Microsoft’s latest leaked prototype: Courier. On an off-note, it’s hilarious to contrast the handwritten everything with the king of monospace fonts! (and previously, my latest interest has been the long-awaited crunchpad.)

But there’s 2 things I’m here to mention: my dream & the obvious rising behind Courier.

Why Courier is Obvious:

First off, how many people do you see carrying around a notebook/folio of some variety? Everyone. The business guys do it for their contacts, dates & files. College kids do it for their class notes. Artsy-kids do it for their scribble-pics. Christians have a habit of doing it for their Bible study/sermon notes. Everyone.

Second: netbook+eReader. Limited computing strikes again, and awaiting for a convergence.

Third: Intel’s atom platform (and I would argue ARM even more!) is ready for this kind of thin-and-goodness. Especially with ssd’s (heck, I’d be happy with an SDHC!)

My Little Dream:

I’m a fan of the UI-customizability of Linux. Always have been: it’s what keeps me away from MacOS. Right now, I’ve got a toolbar that has everything I need in it: time, calendar-on-click, applets & a task-switcher. All this overlays the wasted-space of window-titlebar. Most of the time I maximize my apps, so I can focus. But there are somethings that should be a sidebar: notably a tabbed filemanager (since I already have a tabbed term thanks to tilda).

lxpanel-coloredAnd there’s no reason why a quick photo-viewer, calculator, contacts & datebook cannot also be in this sidebar (especially if cache’d & synced from Google!) All this sidebar stuff is too perfect. Why not make a Window Manager that runs specific apps in specific ‘frames’ (yes, like HTML old-skool style). The frames are resizable & collapsable. Ths is so (similar but) much more useful than a tiling WM.

Next up, I’ve never, ever understood file dialog boxes. I do however understand Delicious’ tagging. It auto-generates recommendations, and why not do this for files?  Linux is built for this: symlinks.

And while we’re at it, why not kill off scrollbars & make everything grab-and-draggable. Just use a modifier key (or both-click). Then we can have the app be like a magnifying glass, with the edges smushed to show you how much more you have down there (in preview-style).

As for all this journally stuff, Xournal is the single-best program I have ever, ever, ever encountered. Multiple-layers? yup. Print to PDF? Yup. Wanna add a new page? Click the ‘next page’ button. It could remove all it’s menus if it just had a ‘preferences’ dialog box. It is the model for any journaling program.

Lastly, mouse-gestures are very hot lately. I don’t use them because I’d like ‘em to be like Courier: context-specific AND list suggested actions, instead of always acting on its own.

Dreams, dreams, dreams.

All I’m sayin’ is if ASUS puts out an Intel Atom dual-screen netbook/eReader next year, or even this year, I’m putting my dreams to work. Just need to solve 2 problems:  the sidebar thinger (update: “devilspie” might be halfway there for me) & handwriting recognition (and I’ve got a prototype system coming this december when classes are out!).

The iPen Review

The iPen, by Finger System, Inc.

First off, sometimes you can judge a book by it’s cover– especially when a marketing department has ahold of the cover. By this I mean the “Ages 5 & up” label. Yes, this IS a kids play toy, and I’m going to try and take it seriously. I hope that doesn’t make me a kid. Likely does.

First Impressions

first 15mins:  holy crap this is fussy! How does this work right at all?

second 15mins:  let’s try to figure some workarounds..

third 15mins:  ok, now with a basic system in place, perhaps there’s a chance.. a very small chance..

last 15mins:  It brings back the good ol’ days of owning a pocket pc.

1 month in: with the right linux-config’d system in place, the iPen has it’s place, and can even replace the need to own a full $1700 tabletPC. For $15, it’s a steal. But the whole repetitive stress thing isn’t any better or worse, but that’s my fault for being tied to this thing for 12hrs /day!

“The System” (My Linux config)

0) You really should use the old-school optical 1mm grid they provide.. graph paper doesn’t cut it. I ended up cutting a 2″x3″ square out & taping it on the corner of my laptop (nearly over the trackpad!) when I’m not at my desk. However, when running in ‘super slow mode’, i need the whole thing. Choose cutting wisely.
1) hold the mouse a bit more upright than a regular pen, especially when not using the grid-pad :(
2) Slow the mouse settings all the way down: xset m 0 0, (or see my ultra-slowed-down xorg.conf)
3) Use xournal to scribble notes & PDF annotate, zoomed in to full-width (150%), unless running ultra-slow, then tis fine zoomed out where the notebook lines are like college-ruled. (yes, i measured). Xournal also supports graph paper, colored paper & custom-paper sizes. Handy for when I rotate the screen. Also, I found having the default right-click to be the ‘hand’ is very handy (like acrobat’s hand/grab-drag-scrolling)
4) Use cellwriter for single character input (aka PocketPC-land!). Takes some config, but it gets pretty good.
5) Firefox plugin: “Grab and drag”!  This is when it hit me: “Don’t try and use a pen like a mouse. Use a pen like a pen!”

The Speed Test

With cell writer config’d & trained (not a hard process at all),
and using the sentence: “The quick brown fox jumps over the lazy dog”:
Typing: “THe quick brown fox jumped over hte lazy dog” is 8-9 seconds, with only 2 errors.
Cellwriter: “the quick brown fox jumped overthe lazy dog.” in 58 seconds, first try, then 44s!, with 2 errors as well.
Handwriting on paper: 13seconds
Xournal: 24seconds.

A 5-6 times increase in time is wretched. Especially if I in-line corrected about 4-6 characters thanks to a shaky nervous hand! No doubt I’ve cellwritten faster since this early test, but I seriously doubt it will ever come close to touch typing. The other variable is that when typing, I type faster than I think, so I’m always stopping to think about what I’m saying. But with cellwriter, I’m writing so slow, I can think about what I’m saying. Trouble is, if it’s too slow, I’m thinking about writing the characters & forgetting about what I’m saying.

Improvements

It’s amazing just how sensitive the nature of handwriting is. There’s 2 very strong components to pencil writing that is lacking with this digital pen.
1) Pencils are pressure sensitive across a gradient, not a binary on/off. You can swipe a pencil and get a line. When you lift a pencil while handwriting, it’s more a light drag across the paper than it is a full 1mm lift. Hopefully I’m explaining this right: the ipen requires a 1mm lifting or dropping of the pen to register a swipe. This is not natural, however oddly enough, when the mouse is super-slow, this problem dissipates, as well as with getting used to it.

2) Tracking. When we lift a pen and move it, it now resides to write in the new location. On the slowest mouse motion, the ‘mousing area’ is still 2″ wide x 1.5″ high. This is hardly a one-to-one (like true tabletPC’s have) with a 13.3″ diagonal screen! Second, this pen is very sensitive and you have to lift the pen a good centimeter off the surface to stop it from moving the mouse cursor (to get the mouse cursor where you want it, relative to the hand-on-paper position). This is also shown when setting down & picking up the pen.. a mouse or trackpad will leave the cursor & mouse, the pen must be set & picked up again.
One last comment, I’d prefer to have a scrollwheel where the right click button is. But some of that is solved by FF’s grab-and-drag plugin. If only that plugin was across all X/GNOME/KDE applications!

Multiple mouse config in Ubuntu

Since I’ve bought an ipen, I need different settings for the pen and trackpad. The trackpad should have all the fun little bits that it came with, 2-finger scrolling & a decent speed, while the ipen, to be useful for writing notes in PDFs needs to be soo much slower (a 3/4 ratio of pen-to-screen).  This setup will of course apply to any multiple input device setup..

  1. backup xorg.conf (in terminal: sudo cp /etc/X11/xorg.conf /etc/X11/xorg.conf-original)
  2. with the mouse plugged in, lets find which device is which:
    1. sudo cat /dev/input/pxaux   ..now touch the trackpad: see funny letters for each motion? Good. (control-c to exit)
    2. sudo gedit /etc/X11/xorg.conf, add these lines:
      Section "InputDevice"
      Identifier "Synaptics Touchpad"
      Driver "synaptics"
      Option "SendCoreEvents" "true"
      Option "Device" "/dev/psaux"
      Option "Protocol" "auto"
      Option "HorizScrollDelta" "0"
      Option "SHMConfig" "on"
      EndSection
  3. Now, config the mouse by the same method, but trying /dev/input/mouse0 .. through mouse4.
  4. Add these lines accordingly:
    Section "InputDevice"
           Identifier "Configured Mouse"
            Driver      "mouse"
            Option      "Protocol" "auto"
            Option      "Device" "/dev/input/mouse4"
            Option      "Emulate3Buttons" "no"
           #Option      "Resolution" "50"
           #Option      "Sensitivity"       "0.24"
           #Option      "ConstantDeceleration" "4"
    EndSection
  5. You’ll notice the last 3 lines are commented out.. I used the ‘constant deceleration’ to slow down my 800dpi mouse-pen. I enver played with the other 2, though they might work as well.
  6. Further, I had to add these lines as well for everything to work:
    Section "ServerFlags"
    Option "AutoAddDevices" "0"
    Option "DontZap" "off" #ctl-alt-back restart-X
    EndSection
    
    Section "ServerLayout"
            Identifier "Default Layout"
            Screen "Default Screen"
            InputDevice "Synaptics Touchpad"
    EndSection

When all is said & done, I also found gsynaptics (sudo apt-get install gsynaptics) which allowed fun things like ‘ipod-scrolling’ and corner/edge events.

Final note: I needed my pen to be slower than even xset m 0 0 could give me, though that was close.

2009-10-22 UPDATE: Instead of EVERYTHING above, I finally got this to work in HAL (which means keep the original /etc/X11/xorg.conf file clean), thanks to removing mouseemu which was always making the usb pen-mouse be reconfig’d to normal acceleration! In ubuntu 9.04, I simply created this file: /etc/hal/fdi/policy/10-x11-input.fdi:

<?xml version=”1.0″ encoding=”ISO-8859-1″?>
<deviceinfo version=”0.2″>
<device>
<match key=”info.capabilities” contains=”input.mouse”>
<match key=”info.product” string=”Finger System Inc. i-Pen Mouse FM-100BN”>
<merge key=”input.x11_options.ConstantDeceleration” type=”string”>3</merge>
</match>
</match>
</device>
</deviceinfo>
While debugging, I confirmed the settings were in lshal & /var/log/Xorg.0.log.

Read Google Calendars from Orage!

Holy crap! My fav toolbar calendar is more than just a calendar! It does alarms & full ICS input & output! With a little scripting & cron, I get the day’s events with one click!

#!/bin/sh
cd ~/tmp
wget http://www.google.com/calendar/ical/--your-private-gcal--url/basic.ics
mv basic.ics calname.ics

Just repeat the wget & mv for all calendars, add an hourly cron job & add the files to orage’s preferences/foreign calendars tab!

Love is simplicity!

A Better Openbox transparency

I’m lately in love with openbox for it’s simplicity and lack of screen-coverage. Sure I could have setup my desktop within xubuntu, but I wanted to expand my horizons.

My original theory was for netbook application, maximizing screen real estate & reducing the hard drive & processor use. But lately, I’ve been toying with xcompmgr, hardly a ‘wise’ use of resources.

While Urukrama has a wonderfully extensive Openbox config page, I didn’t find the “make all inactive windows 60% transparent” like I was looking for.

A little googling gave me the solution I was after, but it was insanly processor/battery intensive! (That’s what ya get for writing an infinite loop! ) At first I tried putting a “sleep” command in the loop, and that did tremendous wonders for retaining processor use, and slowing down my frantic computer-work pace. Still, I wasn’t pleased.

So here, without further ado, is my xcompmgr+transset-df+perl script for setting all non-active windows:

#!/usr/bin/perl -w

# This script is a modification my M.Wallace of the
# original written by Andrei Perhinschi
# and is licensed under the GNU GPL license
# http://www.gnu.org/licenses/gpl.html

# Much thanks goes to Daniel Forchheimer (http://www.forchheimer.se/)
# for creating transset-df and the eutotrans
# script from which this script gets its inspiration

if ( !defined $ARGV[0] || !defined $ARGV[1] || !defined $ARGV[2] ) {
die "Usage: focustran-once <unfocused value> <focused value> <refresh value (secs)>\n";
}

# default values
$trans_val = $ARGV[0];
$opaque_val = $ARGV[1];
$sleep_val = $ARGV[2];

# grab all window IDs
@win_ids = `xwininfo -root -all`;
foreach my $win_id ( @win_ids ) {
unless ( $win_id =~ /has\ no\ name/ || $win_id !~ /0x/ || $win_id =~ /Desktop/ ) {
 $win_id =~ /\ \"/;
 $win_id = "$`";
 $win_id =~ s/\s//g;
 push @id_lines, $win_id;
 }
}

#print "ID_LINES:@id_lines\n";

# find my active window
my $active_id = `xprop -root  | grep "_NET_ACTIVE_WINDOW(WINDOW): window id # "`;
$active_id =~ /\#\s/;
$active_id = "$'";
chomp $active_id;

# set the active window to non-transparent value
system ( "transset-df --id $active_id $opaque_val" );

# make all other windows transparent
foreach my $win_id ( @id_lines ) {
# set active window to opaque_val and old window to trans_val
if ( $win_id ne $active_id ) {
system ( "transset-df --id $win_id $trans_val" );
 }
}

Then just add these lines to ./config/openbox/rc.xml (around line 302 for me):

    <context name="Client">
      <mousebind button="Left" action="Press">
        <action name="execute">
        <execute>perl ~/bin/focustrans-once.pl .6 1 0</execute>
        </action>
      </mousebind>
    </context>

Trouble is, I use mouse-raises windows, not click-to-focus! Anyone got some help for me, be it X11 active window or openbox mouse-motion-detect?