On Jan 20, 2008, at 8:05 PM, TjL wrote:

On 1/20/08, Michael Heinz <[EMAIL PROTECTED]> wrote:
Sounds like you need a rule in Mail.app to run an applescript. It's
doable, but I'm not sure how.

Years ago, I wrote a script to invoke the say command when certain
emails were received. If you're interested in it I can post it.

Yes, but I have no idea how to tell Mail.app:

"Take first line of email body and pipe it to Yojimbo, instructing it
to make it a web archive."

So this is really a "how do I script Apple Mail" question? ;-)

Here's a quick script which should either do what you want, or serve as a good starting point for additional hacking. It works off of the selected messages in the front message viewer (browser) in Mail.

- Jim

== begin script ==

on run
        tell application "Mail"
                set zMessageList to selected messages of message viewer 1
                repeat with zMsg in zMessageList
                        my process_message(zMsg)
                end repeat
        end tell
end run

on process_message(zMsg)
        tell application "Mail"
                set zName to subject of zMsg
                set zURL to my trim_url(content of zMsg)
        end tell
        if looks_like_url(zURL) then
                tell application "Yojimbo"
make new web archive item with properties {name:zName} with contents zURL
                end tell
        else
                display alert "Message body does not look like url."
        end if
end process_message

on trim_url(zURL)
        set zWhitespace to {space, return, ASCII character 10, tab}
        set zStartIndex to 1
        set zEndIndex to length of zURL
        repeat with i from 1 to zEndIndex
                if character i of zURL is not in zWhitespace then
                        set zStartIndex to i
                        exit repeat
                end if
        end repeat
        repeat with i from zEndIndex to zStartIndex by -1
                if character i of zURL is not in zWhitespace then
                        set zEndIndex to i
                        exit repeat
                end if
        end repeat
        return text zStartIndex through zEndIndex of zURL
end trim_url

on looks_like_url(zURL)
        set zProtocols to {"http://";, "https://";, "mailto:"}
        repeat with zProto in zProtocols
                if zURL starts with zProto then
                        return true
                end if
        end repeat
        return false
end looks_like_url

== end script ==

--
------------------------------------------------------------------
This message is sent to you because you are subscribed to
 the mailing list <yojimbo-talk@barebones.com>.
To unsubscribe, send mail to: <[EMAIL PROTECTED]>
List archives:  <http://www.listsearch.com/yojimbotalk.lasso>
Have a feature request, or not sure if the software's working correctly? Please send mail to: <[EMAIL PROTECTED]>

Reply via email to