Monday, October 5, 2009

How to learn English

For Japanese, English is strange, non-understandable and mysterious language. A Maximum problem of this issue is ultra differences between those languages system. For us, to learn English means to get start for long long journey to India.

If you can read Japense, follow is a funny series that tells and helps you how to study English.

Of corse, we can not get success within a few days or months, need some years hard study. But it shouldn't hard way. If we chould, tt's going to be funny way, isn't it?

Saturday, October 3, 2009

Wrap script for Thunderbird and Mail.app

If you saved script as launch_mail_compose.applescript and launch_thunderbird_compose.sh, Follow command works well for both FreeBSD/Linux and Mac OS X.
case "$(uname)" in
FreeBSD|Linux)
    MUACOMPOSER=launch_thunderbird_compose.sh
    ;;
Darwin)
    MUACOMPOSER=launch_mail_compose.applescript
    ;;
esac

${MUACOMPOSER} \
  to="hoge@example.com,moge@example.com" \
  cc="soge@example.com" \
  subject="Test sample shiken tesuto" \
  attach="/pathto/attachfile.tgz" \
  body="$(cat /pathto/mailtemplete)"

Thunderbird launch wrapper

This is a little wrapper script to launch Thunderbird mail composer, against for Mail.app compose script.
#!/bin/sh

for target in ${@+"$@"}
do
    case "${target}" in
    to=*)
      to="${target#*=}"
      ;;
    cc=*)
      cc="${target#*=}"
      ;;
    sender=*)
      sender="${target#*=}"
      ;;
    subject=*)
      subject="${target#*=}"
      ;;
    attach=*)
      attach="file://${target#*=}"
      ;;
    body=*)
      body="${target#*=}"
      ;;
    esac
done

exec thunderbird -compose "to=${to},cc=${cc},sender=${sender},subject=${subject},attachment=${attach},body=${body}"

Mail.app compose script, my first AppleScript experience!

How can I get to do automation mail composing like FreeBSD and Thunderbird doing? This weekend I have tried to make auto mail composing script by AppleScript. This is my first AppleScript experience! How do you feel of following script? It looks pretty good ;-)
#!/usr/bin/osascript

on run argv
 set argc to count item of argv
 
 repeat with i from 1 to argc
  set targetlist to textToList(item i of argv, "=")
  set target to item 1 of targetlist
  set value to item 2 of targetlist
  
  if target is "to" then
   set mailto to textToList(value, ",")
  else if target is "cc" then
   set mailcc to textToList(value, ",")
  else if target is "sender" then
   set sender to value
  else if target is "subject" then
   set subject to value
  else if target is "attach" then
   set attach to value
  else if target is "body" then
   set body to value
  end if
 end repeat
 
 return newMail(mailto, mailcc, sender, subject, attach, body) of me
end run

on newMail(mailto, mailcc, sender, subject, attach, body)
 global newMail_mailto
 global newMail_mailcc
 global newMail_sender
 global newMail_subject
 global newMail_attach
 global newMail_body
 
 set newMail_mailto to mailto
 set newMail_mailcc to mailcc
 set newMail_sender to sender
 set newMail_subject to subject
 set newMail_attach to attach
 set newMail_body to body
 
 tell application "Mail"
  set composeWindow to make new outgoing message
  set visible of composeWindow to true
  
  tell composeWindow
   set sender to newMail_sender
   set subject to newMail_subject
   set content to newMail_body
   
   set limit to count item of newMail_mailto
   repeat with i from 1 to limit
    make new to recipient with properties {address:item i of newMail_mailto}
   end repeat
   
   set limit to count item of newMail_mailcc
   repeat with i from 1 to limit
    make new cc recipient with properties {address:item i of newMail_mailcc}
   end repeat
   
   make new attachment with properties {file name:newMail_attach} at after last paragraph
  end tell
  
  (* Signature should be added after attachment treatment complete.
  If signature is added before attachment work complete, attachment
  treatment overwrites signature config and it turns into "none" signature. 
  I guess it's a bug of Mail.app. Following delay command is workaround of 
  this issue. *)
  delay 1.5
  set message signature of composeWindow to signature newMail_sender
 end tell
end newMail

on textToList(target, delimiters)
 set resultlist to {}
 
 set delimiters_org to text item delimiters of AppleScript
 set text item delimiters of AppleScript to delimiters
 set limit to count text item of target
 repeat with i from 1 to limit
  set end of resultlist to i
  set item i of resultlist to text item i of target
 end repeat
 set text item delimiters of AppleScript to delimiters_org
 return resultlist
end textToList
License is 2-term BSD License.