Sunday, November 19, 2006

My current hack for syncing text files (well, _a_ text file) between a Mac and a Palm, using the MacNoteTaker conduit - NoteTakersFriend.sh:

#!/bin/bash
#It seems like growlnotify can not be launched by NoteTakersFriend

#could probably rewrite simply with rsync
#gotta wait until the first sync is done
#watchfile /Users/Surly/Documents/Palm/Users/Palm\ Users
#-60 second interval

#IF Conduit Manager is not an active process OR if that UserData file exists then execute NoteTakersFriend
#watchedfileboils
#this is definitely checkable through Applescript (see itunes status mod.)
#newer=ls -t /Users/Surly/Documents/Palm/Users/Surly/NoteTaker/remind*|awk '{print $1}';
#simpler: TIME=`date | awk '{print $4}'`

#DEBUGGING:
#It seems like something sometimes gets screwed up such that this file gives no echo output.
#The cure to this sleeping sickness seems to be somewhere in running (at least pasting the
#commands into a sh shell), thecure.sh (basically commenting out the if [ "$?" != "0" ] line and it's fi terminator)
SyncMode=`diff /Users/Surly/Documents/Palm/Users/Palm\ Users /Users/Surly/Documents/Palm/Users/Palm\ UsersSyncOnce |cut -c 112-117`;
newer=`(set \`ls -t /Users/Surly/Documents/Palm/Users/Surly/NoteTaker/remind*|awk '{print $1}'\`; echo $1)`
#echo "$newer"
#if (lastntfif [ "$SyncMode" = "differ" -a "$newer" = "/Users/Surly/Documents/Palm/Users/Surly/NoteTaker/remind.txt" ]; then # = for strings and -eq for numbers
# if [ls -t /Users/Surly/Documents/Palm/Users/Surly/NoteTaker/remind*|awk '{print $1}'=~s/remindmergetracker
#if (change date of NoteTaker/remind.txt >change data of remind.txt)

#deal with line feed discrepancy
#merge osx old palm
userspath="/Users/Surly/Documents/Palm/Users/";
fileold="/Users/Surly/Documents/Palm/Users/Surly/tmp/remind.txt";
file="/Users/Surly/remind.txt";
filepalm="/Users/Surly/Documents/Palm/Users/Surly/NoteTaker/remind.txt";
filemerged="/Users/Surly/Documents/Palm/Users/Surly/tmp/remind.txt.merged";


cp $filepalm $filepalm.tmp
tr '\015' '\012' <$filepalm.tmp > $filepalm
rm $filepalm.tmp
#instead of diffing palm and laptop versions, just check last time
#NoteTaker/remind.txt was touched
diff -q "$file" "$filepalm" >/dev/null;
if [ "$?" != "0" ]; then #$?==0 when files are identical (no differences)
#if [ diff -q "$file" "$filepalm" >/dev/null 2>&1]; then
#echo "$file1 and $file2 differ"
merge -p $file $fileold $filepalm >$filemerged
cp $fileold $fileold.1
cp $file /Users/Surly/remind.bak
cp $filemerged $filepalm
cp $filemerged $file
cp $filemerged $fileold
#cp $userspath/Surly/tmp/remind.txt.merged
#cp $userspath/Palm\ UsersWriteOnce $userspath/Palm\ Users
cp $userspath/Palm\ UsersSyncOnce $userspath/Palm\ Users
touch $userspath/Surly/NoteTaker/remindmergetracker
#the assumption here is that nothing happens on the palm between the
#read sync and the write one - i.e., days do not go by
#defense against such intervening stretches? Maybe on reboot cp ReadPalm to default

#another possible loophole: Conduit Settings is open, NTF runs, then Conduit
#Settings closes, saving its prior settings
#open -a /Applications/Palm/Conduit\ Manager
echo "HotSync again to synchronize NoteTaker" | /usr/local/bin/growlnotify -s -a /Applications/Palm/HotSync\ Manager
#man 1 growlnotify for help
echo "NoteTaker sync mode =>2: Sync with Palm"
fi
#identical files
#NoteTaker/remind.txt was newer than
else
if [ "$SyncMode" = "differ" ]; then
echo "NoteTaker sync mode 1: Read from Palm"
else
echo "NoteTaker sync mode 2: Sync with Palm"
fi
fi


#manual sync again?
#if so, then must worry about even or odd number of syncs
#or else come up with some kind of timing gimmick or something

#TO automate for an entire directory of synched files modify:
#for file1 in *; do
#for file2 in *; do
#if [ "$file1" != "$file2" ]; then
#if [ ! diff -q "$file1" "$file2" >/dev/null 2>&1 ]; then
#echo "%file1 and $file2 are identical"
#fi
#fi
#done
#done


I hope to document this in the future, but basically I just set NoteTaker conduit settings (to read from Palm, write to Palm, whatever) through HotSync Manager and then copied the Palm Users file to those named in the script.

Tuesday, November 14, 2006

pluck - A perl script to simplify saving web pages for offline browsing on a Palm

Plucker Desktop, the program to convert web pages and text files into a format readable on the Palm (using the Plucker viewer), is purported to not work on Intel Macs. Whatever - I always found it a very clicky program and have wanted for years to install a command-line equivalent. Stymied by problems with compiling the Plucker Python distiller, I looked briefly at payware iSilo, but it, too, is not yet working on Intel. I dug around in the Plucker Python distiller and found a version of the Python scripts which can be run directly by just plopping them wherever.

Then I wrote a simple perl script for processing those .webloc files that I drag off the [Safari|Shiira] address bar:

#!/usr/bin/perl -w
@files = ;
foreach $file (@files) {
if ($file=~/\s/)
{$newfile=$file;
$newfile=~s/\s/_/g;$newfile=~s/\'//g;$newfile=~s/\#//g;
$newfile=~s/\&//g;$newfile=~s/\://g;$newfile=~s/\;//g;
$newfile=~s/\|//g;$newfile=~s/\?//g;$newfile=~s/\"//g;
$newfile=~s/\(//g;$newfile=~s/\)//g;$oldfile=$file;
$oldfile=~s/ /\\ /g;$oldfile=~s/\'/\\'/g;$oldfile=~s/\;/\\\\;/g;
$oldfile=~s/\&/\\\&/g;$oldfile=~s/\:/\\\:/g;
$oldfile=~s/\|/\\\|/g;$oldfile=~s/\?/\\\?/g;
$oldfile=~s/\"/\\\"/g;$oldfile=~s/\(/\\\(/g;
$oldfile=~s/\)/\\\)/g;
`mv $oldfile $newfile`;
print "mv $oldfile $newfile\n";
}
}

$i=0;
@files = ;
foreach $file (@files) {
$URL=`strings $file/rsrc | grep http | sed '/^.http/s//http/' | head -1`;
$URL=~s/\s+//g;
$URL=~s/\//;
$URL=~s/\<\/string\>//;

print $URL;print "\n";
$originalfile=$file;
$justfilename=$file;
$justfilename=~s/\/Users\/Surly\/plucker\/to-pluck\///;# WITH .webloc
$pdbname=$justfilename;
$pdbname=~s/\.webloc//;
$pdbname=substr($pdbname,0,20);
$p='/Users/Surly/Documents/Palm/Users/Surly/Files\\ to\\ Install/';
`/Users/Surly/bin/PyPlucker/Spider.py --maxdepth=1 --home-url=$URL -f $p$pdbname`;
`mv $originalfile /Users/Surly/plucker/plucked/$justfilename`;
}

Yeah, it's ugly, but it works.

Then it was necessary to use Fink to install netpbm for processing some of the image files. This failed on jpegs, and even though I had set up ImageMagick (twice, since Fink also did an install) and had set image_parser = ImageMagick in .pluckerrc Spider.py was seemingly still defaulting to netpbm. Anyhow, I noticed that there were some more image processing settings under the [POSIX] section of the .pluckerrc file so I installed libjpeg and then in the .pluckerrc file set djpeg_program = djpeg. And now it all seems to work.

What's left to do: devise a scheme for handling the more complicated plucking jobs: like those that require altering the default maxdepth value (1 seems _so much_ better than 2) or those that need special URL matching; Folder Actions for automating the plucking; catching errors in parsing and not moving the .webloc file under those circumstances.

The bottom line: Plucking on an Intel Mac is not that hard to set up.

Monday, November 13, 2006

Compatibility problems between old (2.1.something) and new (2.9.something) versions of Octave - there are a lot of them. Apparently many of them are for "compatibilty" with Matlab, while sacrificing (fairly draconianly, in some cases) backward compatiblity with Octave.


  1. The old method of setting the path where Octave looks for other function files has changed from setting a LOADPATH environment variable in .octaverc to something like this:
    addpath (genpath ("~/Library/Octave"));
  2. Aquaterm, the way to get Octave to plot in OS X with Gnuplot but without X11, is displaying some kind of wonky behavior in its 1.0.2 incarnation. This may be entirely Aquaterm's fault - the old version (0.3?) was also wonky and required a "close all" command in Octave to get old plot windows killed. I'm still working on this, but excising the "close all" commands at least allows a function to plot to the same windows when called twice.
  3. At some point back in 2004, Octave switched from defaulting to column vectors to defaulting to row vectors because that's what Matlab does. If you routinely use the construction
    for i=1:n, x(i)= whatever ; end;,
    this is a serious monkey wrench heading your way.

    The simplest solution that I have found so far is to go through the code and replace
    x(i)= constructions with x(i,:) constructions. This will ensure backward compatibility of the script.


There are some nice features in this new version of Octave, including allowing matrices of arbitrary dimensionality.

Thursday, November 09, 2006

I'm switching (at least temporarily) to the Shiira web browser for three reasons:

1) Firefox is the only OS X browser that works with Gmail's keyboard shortcuts, but all browsers run out of memory eventually so a second browser is needed for actual browsing.

2) Safari is great, but the new version (2.0.4) has serious problems with keyboard navigation (page up/page down/home/end keys are unresponsive, and tabbing gives undesired results).

3) Shiira (1.2.2) finally has a substitute for Firefox's keyword searches and Safari's AcidSearch add-on: it is called "custom search engines" and is found under the Window menu. And like everything else on Shiira, it works.