First, I had to tackle the problem of automating ssh/scp actions because I have a password on my zaurus. I use some expect scripts to copy to/from the zaurus:
CODE
zcopyto:
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set source [lindex $argv 3]
set dest [lindex $argv 4]
spawn sh -c "scp '$source' $user@$host:$dest"
expect "assword:" {send $pass\r}
expect eof
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set source [lindex $argv 3]
set dest [lindex $argv 4]
spawn sh -c "scp '$source' $user@$host:$dest"
expect "assword:" {send $pass\r}
expect eof
This script takes command line arguments and feeds them to an scp command. Note that you should escape spaces and wildcards in filenames, if used.
CODE
zcopyfrom:
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set source [lindex $argv 3]
set dest [lindex $argv 4]
spawn sh -c "scp $user@$host:$source '$dest'"
expect "assword:" {send $pass\r}
expect eof
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set source [lindex $argv 3]
set dest [lindex $argv 4]
spawn sh -c "scp $user@$host:$source '$dest'"
expect "assword:" {send $pass\r}
expect eof
Likewise, this script copies from the zaurus to my computer.
CODE
zremovefrom:
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set file [lindex $argv 3]
spawn ssh $user@$host
expect "assword:" {send $pass\r}
send "rm $file\r"
send "exit\r"
expect eof
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
set file [lindex $argv 3]
spawn ssh $user@$host
expect "assword:" {send $pass\r}
send "rm $file\r"
send "exit\r"
expect eof
Deletes the given file from the zaurus.
CODE
zclearinbox:
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
spawn -noecho ssh $user@$host
expect "assword:" {send $pass\r}
send "cat /dev/null > /home/zaurus/Documents/Text_Files/inbox.txt\r"
send "exit\r"
expect eof
#!/usr/bin/expect -f
set user [lindex $argv 0]
set host [lindex $argv 1]
set pass [lindex $argv 2]
spawn -noecho ssh $user@$host
expect "assword:" {send $pass\r}
send "cat /dev/null > /home/zaurus/Documents/Text_Files/inbox.txt\r"
send "exit\r"
expect eof
Finally, this expect script simply empties out a text file on the zaurus I use as an idea scratchpad. I call this script after another script that imports the data into my todo list on my mac.
I use these scripts as glue in this large applescript that does all the syncing:
CODE
--
--
-- Settings
--
--
set the_user to "zaurus"
set the_pass to "<yourpass>"
set the_iP to "<yourip>"
set toZDirectory to "Macintosh HD:Users:dave:Desktop:ToZ"
--
--
-- Process Zaurus Inbox File
--
--
-- Get the inbox file from the zaurus via Samba
set zInboxFile to quoted form of "/home/Main_Memory/Text_Files/inbox.txt"
set localInboxFile to "Macintosh HD:tmp:inbox.txt"
set cmd to ("cd /tmp; smbget -n -q -u " & the_user & " -p " & the_pass & " smb://" & the_iP & zInboxFile & "; echo 0" as Unicode text)
do shell script cmd
-- Read through the inbox file
tell application "Finder"
set InboxFile to paragraphs of (read file localInboxFile)
repeat with nextLine in InboxFile
if length of nextLine is greater than 0 then
-- Add the line to the KGTD inbox
tell application "OmniOutliner Professional"
set ThisDocument to first document
tell ThisDocument
set InboxSection to (first section whose note contains "meta_inbox")
make new row at beginning of rows of InboxSection with properties {topic:nextLine}
end tell
end tell
end if
end repeat
-- Erase temp file
move file localInboxFile to trash
end tell
-- Clear the inbox on the Zaurus
set cmd to ("/Users/dave/bin/zclearinbox " & the_user & " " & the_iP & " " & the_pass)
do shell script (cmd)
--
--
-- Sync Crossword Puzzles
--
--
do shell script ("/Users/dave/bin/getpuz.sh")
--
--
-- Sync ToZ Directory
--
--
tell application "Finder"
if (the file (toZDirectory & ":BBC News.pdb") exists) then
set a to quoted form of POSIX path of (toZDirectory & ":BBC News.pdb")
set cmd to ("/Users/dave/bin/zcopyto " & the_user & " " & the_iP & " " & the_pass & " " & a & " " & "/mnt/card/Documents")
do shell script (cmd)
move file (toZDirectory & ":BBC News.pdb") to trash
end if
-- TODO: copy all files here into appropriate zaurus folders according to type
end tell
--
--
-- Sync iTunes Playlist
--
--
tell application "iTunes"
set myPlaylist to playlist "ToZaurus"
repeat with aTrack in (get every track of myPlaylist)
set fileName to location of aTrack
set a to quoted form of POSIX path of fileName
set cmd to ("/Users/dave/bin/zcopyto " & the_user & " " & the_iP & " " & the_pass & " " & a & " " & "/mnt/card/Documents/Music_Files/")
do shell script (cmd)
--TODO: remove track from the playlist
end repeat
end tell
--
--
-- Done
--
--
display dialog ("Sync Done.")
--
-- Settings
--
--
set the_user to "zaurus"
set the_pass to "<yourpass>"
set the_iP to "<yourip>"
set toZDirectory to "Macintosh HD:Users:dave:Desktop:ToZ"
--
--
-- Process Zaurus Inbox File
--
--
-- Get the inbox file from the zaurus via Samba
set zInboxFile to quoted form of "/home/Main_Memory/Text_Files/inbox.txt"
set localInboxFile to "Macintosh HD:tmp:inbox.txt"
set cmd to ("cd /tmp; smbget -n -q -u " & the_user & " -p " & the_pass & " smb://" & the_iP & zInboxFile & "; echo 0" as Unicode text)
do shell script cmd
-- Read through the inbox file
tell application "Finder"
set InboxFile to paragraphs of (read file localInboxFile)
repeat with nextLine in InboxFile
if length of nextLine is greater than 0 then
-- Add the line to the KGTD inbox
tell application "OmniOutliner Professional"
set ThisDocument to first document
tell ThisDocument
set InboxSection to (first section whose note contains "meta_inbox")
make new row at beginning of rows of InboxSection with properties {topic:nextLine}
end tell
end tell
end if
end repeat
-- Erase temp file
move file localInboxFile to trash
end tell
-- Clear the inbox on the Zaurus
set cmd to ("/Users/dave/bin/zclearinbox " & the_user & " " & the_iP & " " & the_pass)
do shell script (cmd)
--
--
-- Sync Crossword Puzzles
--
--
do shell script ("/Users/dave/bin/getpuz.sh")
--
--
-- Sync ToZ Directory
--
--
tell application "Finder"
if (the file (toZDirectory & ":BBC News.pdb") exists) then
set a to quoted form of POSIX path of (toZDirectory & ":BBC News.pdb")
set cmd to ("/Users/dave/bin/zcopyto " & the_user & " " & the_iP & " " & the_pass & " " & a & " " & "/mnt/card/Documents")
do shell script (cmd)
move file (toZDirectory & ":BBC News.pdb") to trash
end if
-- TODO: copy all files here into appropriate zaurus folders according to type
end tell
--
--
-- Sync iTunes Playlist
--
--
tell application "iTunes"
set myPlaylist to playlist "ToZaurus"
repeat with aTrack in (get every track of myPlaylist)
set fileName to location of aTrack
set a to quoted form of POSIX path of fileName
set cmd to ("/Users/dave/bin/zcopyto " & the_user & " " & the_iP & " " & the_pass & " " & a & " " & "/mnt/card/Documents/Music_Files/")
do shell script (cmd)
--TODO: remove track from the playlist
end repeat
end tell
--
--
-- Done
--
--
display dialog ("Sync Done.")
The first section in the applescript is obvious settings. The toZDirectory variable is a directory I use as a Mac->Zaurus outbox. The idea is to move these files to the Zaurus; later, I intend to implement a Z->Mac one too.
The second section grabs the data from my Zaurus inbox.txt file and imports it into my task list system that uses OmniOutliner, called KGTD. Each line in the inbox is an item in the outline. Then, it clears out inbox.txt.
The next section runs a script that downloads Across Lite puzzles and copies them to the Z. I haven't posted that one, but I can if anyone is interested.
The next section handles my Mac->Z outbox directory. I haven't finished this section yet. Right now, it only moves my daily BBC news file for Opie Reader. This is generated every day via JPluck and a cron job. If anyone is interested in a JPluck.app bundle, the data file for the BBC news, and details on setting this part up, let me know. Ultimately, I want to move every file put in this directory to the Z, filtered into different places based on file type (Text_Files, Photo_Files, etc.).
The final section copies mp3s from an iTunes playlist to the Z. Ultimately, it should then remove the file from the playlist.
Has anyone else attempted to put together a similar system?
Dave.