« Random Tidbits | Main | Creeping Obsolecence »
June 05, 2003
AppleScript Pain
It seems that recently my ability to send email from my local laptop is being denied by the anti-spam crowd. Essentially they consider my DSL connection to be a possible venue for spam, and I can see why they believe this. Unfortunately, this has the side effect of making my life a lot more difficult. For some unknown reason my local mail-server does not inform me when a message isn't sent properly. I only discovered this the other day when people I email normally informed me they never received a message.
Solution: I have a machine with a static IP that is clean, why not use it?
Means to accomplish this:
1) Re-compile sendmail to use password authentication for sending
2) Create a tunnel from your machine to the host machine for sending email
I choose route 2, as route 1 could be damaging/intrusive to other users on the system. To start with ssh has a wonderful port forwarding utility, so a simple command like:
ssh -L5000:deadmime.org:25 deadmime.org -N
does wonders. This will forward any local connection to port 5000 out to port 25 on my static deadmime.org host. The -N simply states that I don't need a command line, I'm only forwarding ports. Port 5000 was selected because you need to run as root to enable any privileged ports (i.e. 25).
This works fairly well until you realize that under OSX when your laptop falls asleep, SSH connections bork big time. So there needs to be some form of error handling in such a script, i.e. test the connection, check the output, if there is bad output, kill the connection, and re-establish it. At this point we've now stepped beyond my scripting abilities, and have stepped into an area of unknown bewilderment.
A new line of thinking was needed, and it was now that I remembered that Mail.app (the OS X mail application) can run AppleScript. Why not enable an AppleScript to intercept any send commands, create the connection, and then kill itself. Yes it wouldn't be efficient, but it would solve the stale SSH handle problem. More importantly it would only be needed to run when I'm trying to send an email, thus I won't have to check if my connection is up and running or not! Plus this should be a fairly simple script to author, right? Wrong.
AppleScript has to be one of the most confusing scripting languages in existence. Who would develop an editor that doesn't have a find command?!?! I have yet to be able to understand a bit of what would be necessary to accomplish this goal, and I spend a lot of time programming on a daily basis! If any readers have suggestions on how to enable this via AppleScript, or even how to fix my up my shell script, I'd love to hear it. Comments appreciated.
So far my AppleScript can be found below and has some major problems. Like opening a new Terminal each time this is run.
tell application "Mail"
tell application "Terminal"
activate
delay 1
do script with command "ssh -L5000:deadmime.org:25 deadmime.org -N"
error number -128
end tell
end tell
Posted by Dan at June 5, 2003 07:41 AM
Comments
Not sure if you still care, but I think you're looking for do shell script(http://developer.apple.com/technotes/tn2002/tn2065.html)
Posted by: anode at June 20, 2003 08:30 PM
To avoid the extra open window, if you still are working on it, use this line first, it has worked well for me so far. Hope it helps
close window 1
Posted by: Brian at November 17, 2003 03:54 PM
I used the following it Apple script editor:
do shell script "ssh -N -2 -4 -c blowfish wfm@blah.net -L 10143/blah.net/143 -L 1025/blah.net/25"
Posted by: William Macdonald at April 18, 2004 11:30 AM