Thursday, February 26, 2004

Enter Search String and Send Now

John Gruber had the bright idea of using a menu script to override Mailsmith’s Send Now command. Send Now has the same keyboard shortcut as Enter Search String in BBEdit, so if he has text selected in the message window, he probably meant to enter the search string rather than send the message. In this circumstance, Gruber’s script asks for confirmation that you want to send the message. Below is a modification of his script. My version sets the search string to the selected text and then doesn’t send the message. In other words, the script guesses the appropriate action and then does it.

on enterSearchString()
    tell application "System Events"
        tell application process "Mailsmith"
            click menu item "Enter Search String" of menu "Search" of menu bar 1
        end tell
    end tell

on menuselect()
    tell application "Mailsmith"
        tell message window 1
            if (selection as text) is not "" then
                my enterSearchString()
                return true
                return false
            end if
        end tell
    end tell
end menuselect

One problem is that if the message isn’t sendable (i.e. if no recipients have been entered), then the menu item will be disabled and the menu script can’t be used.

4 Comments RSS · Twitter

I tried John Gruber's version earlier with no problems. When I try this version with no text selected, the email sends fine.

If I have text selected, I get this error:
NSReceiverEvaluationScriptError: 4 (application error code 1).

Any ideas?

No, I hadn't.
Now, I did.
Yes, it works.
Thank you much!

This will check to make sure the os is 10.3 or later (UI scripting was added in 10.3) and let people know if they need to activate UI scripting. I haven't tested this because I don't have mailsmith. Let me know if it works please. Click here to open the script in script editor.

Leave a Comment