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.

No comments: