PDA

View Full Version : Email / Compress and Email script for Thunderbird


grotsasha
Feb 18, 2006, 07:19 AM
The Thunderbird script works only with latest nightly builds (won't work on 1.5 due to a bug in Thunderbird). Current Thunderbird version (2.0 ) has a bug that makes PF hang and wait till you send the mail and quit Thunderbird, which is very inconvinient.


--------------------------------------------------------------

I also began to play a bit with Thunderbird. It's not scriptable, but it accepts command line arguments, so I started with the idea to do it with a "do shell script" applescript command. But it didn't want to work. Getting out of my nerves because everything seemed to be correct, I finally found the reason: unfortunately Thunderbird 1.5 has a bug that prevents making attachments from the command line. :twisted:

The -compose command line argument doesn't work correctly in Thunderbird 1.5 due to a parsing bug. It generates the compose message window but none of the fields are filled in. The only workaround is to use a mailto: URL. However, this prevents you from passing an attachment due to a security restriction.Need to wait until version 2.0 until they fix it. I use Thunderbird, because it's the only mail client that supports all standard russian encodings and handles them correctly, the option to force it to compose in UTF-8 is also important to me, as I have a strange style of writing messages in a mix of russian, french and german sometimes. So Apple Mail for example gets confused and send them as Chinese or something like that :)

grotsasha
Feb 19, 2006, 05:33 AM
I just discovered that they fixed this Thunderbird bug a week ago in their recent nightly build (1.6alpha2). So I just downloaded it and made a very quick and dirty AppleScript (i.e. without any tests, doesn't contain subject, etc, no errors output, etc.) that already works with this nightly build with PF on my machine. I'll elaborate it of course.

Thunderbird command line syntax for attachments is the following:
/<path>/thunderbird-bin -compose "attachment='file:///path/myfile.jpg'"
Further information on Thunderbird command line syntax can be found on this page (http://www.mozilla.org/docs/command-line-args.html/url)

And here's my "3-minutes-effort-sorry" script:

on send_mail(email_subject, email_message, email_sender, email_recipient, email_files)

set thunderbird_bin to "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose "

--Thunderbird needs an URL path
set email_files to "attachment='file://" & email_files & "'"

do shell script thunderbird_bin & quoted form of email_files
end send_mail

It probably contains as many potential bugs as the quantity of characters in the code, but it works for me :)

One of known issues with this script is: if Thunderbird is already running it will not work (it launches a second copy and fails) So it should be fixed. Unfortunately the built-in mozilla x-remote-client, which can attach to an existing thunderbird process doesn't work in OS X. This script can't attach more than one file yet, but this is a bit tricky to correct as I get only a global email_files variable, and thunderbird needs to have these multiple files separated with commas...


__________________________________________________ __________________

Here followed a long discussion with flip who helped me a lot to debug my script for Thunderbird mail client. If you want to read about my painful process of getting used to this strange language that is AppleScript, I've moved this thread to Anything Goes.

neilio
Feb 19, 2006, 10:23 AM
I've tweaked the name of this thread to be more descriptive and stickied it so that others can take advantage of this great scripts before we integrate them into Path Finder.

Thanks for sharing, guys!

grotsasha
Feb 20, 2006, 02:15 PM
Ta, ta!!!! It works!!!!!!!!!! :) :) :)

I just made it crash myself with my "display dialog" debugging, but that helped me a lot to figure out a very fine bug!! I'm proud of myself 8) 8) :D

Ok: Attention, please! Here's a final public alpha (:lol: ) release of the script for Thunderbird mail client, made in close collaboration with flip (need to know your real name, for such serious things! :) )

README:

Works only with the latest Thunderbird nightly build (1.6a1 built after 15th of February)
Known issues:
- will fail if Thunderbird is already running (launches a second copy and fails). This is very difficult to fix (if at all possible)
- while attaching multiple files for the email command, will not include the first one (in alphabetical order). It doesn't concern the email&compress command (all files are correctly included and compressed in one archive). This should be fixed inside PF (not my fault :roll: ) This issue is the same for all email clients actually
- will maybe have problems if you have some difficult non-ASCII names or strange path to your files

HOWTO:

Until it will be included in one or other form in PF installation, you should copy and paste the text below into the AppleScript Editor, save it as mail_send_message.scpt and replace the original script of the same name (make a backup first just in case) inside the Path Finder.app/Contents/Frameworks/CocoatechAppleScript.framework/Versions/A/Resources/Scripts

The software is provided as is, without any warranty and blah, blah...You can modify it as you like (Am I looking professional? 8) :lol:

Ok, enjoy:

on send_mail(email_subject, email_message, email_sender, email_recipient, email_files)
try
set thunderbird_bin to "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose "
set email_subject to "subject=" & email_subject
set email_recipient to "to=" & email_recipient
set email_message to "body=" & email_message
set attachments to "attachment='"


repeat with a_file in email_files
if a_file as string is (last item of email_files) then
set attachments to attachments & "file://" & a_file
else
set attachments to attachments & "file://" & a_file & ","
end if
end repeat

set arguments to email_subject & "," & email_recipient & "," & email_message & "," & attachments & "'"

do shell script thunderbird_bin & quoted form of arguments

on error error_message number error_number
log error_message & " " & error_number
end try

end send_mail

flip
Feb 20, 2006, 02:32 PM
Ta, ta!!!! It works!!!!!!!!!! :) :) :)

I just made it crash myself with my "display dialog" debugging, but that helped me a lot to figure out a very fine bug!! I'm proud of myself 8) 8) :D
Congrats! :D

(need to know your real name, for such serious things! :) )
The name is Philippe Martin. You can call me Philippe, or Flip, if you're feeling lazy. But I claim no credit for the script, you did it! :)

grotsasha
Feb 20, 2006, 03:25 PM
Thanks a lot, Philippe!

As the last thing I just checked how it will behave with *really* silly paths and file names. And yes, it get problems. There is no way it will work if the name of your folder contains a mix of all languages and plenty of spaces... But normally one doesn't do such things :) If several files have difficult names, but are inside a "normal" folder/path then PF get care of them if you choose a compress option, give all this nonsense a name "Archive" and it works. If you don't use compress it fails.
So, ideally, one need the URL encode applescript command inside PF.

r00st3r
May 27, 2007, 01:14 PM
I'm curious to know if this script works with TB 2? In addition, can this script be easily modified to work in iPhoto? Our local Mac User Group has some TB users (and I have many clients that are Mozilla/TB users) that would really like to be able to send images from iPhoto through TB. It looks very promising as is though!

Thanks in advance!

(Off to compare your script with the ones for eudora/mail/entourage/aol in iPhoto)

grotsasha
May 28, 2007, 01:04 AM
Well, this script as it is written above will not work because internal structure of how Path Finder handles scripts for different email clients has changed since. I remember that when Thunderbird was out I played with it to rewrite it, but I've got into one problem - if Thunderbird is already launched, the script will launch a second copy of Thunderbird and fail. This is a Thunderbird problem, not Path Finder's. I should take time and rewrite and test it to integrate it to PF, I'll try to do it when I have time. Thunderbird is a little bit painful to workaround in AppleScript since it doesn't support it, I'm just building a string of command line arguments and I remember that debugging it was kind of painful. But I'll take a look.

r00st3r
May 28, 2007, 12:35 PM
I decided to test it out while I awaited your reply and so far it works, mostly. :)
I quit TB (v 2.0) and then I setup iPhoto properly (custom icon & the AppleScript file). Next I selected a single image and clicked the email button. All went as it should until it came to the compose window. It had user@host in the body above my signature (correct placement, incorrect value), it had the file attachment name in the to field and the attachment window showed the internal HD icon. So far, the issue I am looking at is figuring out how to place the attachment in the attachment pane. Next I will address the default subject (i forget now if it was correct or not) and then I will test multiple attachments.

I do say though, your base script works at about 80% currently. :D

periferral
Jun 26, 2007, 07:17 PM
i tried this with TB2. Using PF .. i right clicked on a pdf and chose email.

It opened TB with the attachment in a compose window.

However, the PF is now hung. I have to quit Thunderbird to release whatever is locked up and then PF is usable again.

Also r00st3r, how did you get this working with iphoto. When i open iphoto, it still opens mail.app

grotsasha
Jun 27, 2007, 01:04 AM
That's right, Thunderbird's process hangs PF, because PF waits a signal that the task it launched is completed, and Thunderbird doesn't do it (it was different with TB 1.x btw) . That's why we didn't include this script in PF. There's nothing we can do until this Thunderbird behaviour changes. (plus the fact that if Thunderbird already runs, it launches second copy and fails is also kind of bad).

r00st3r
Jul 07, 2007, 10:44 PM
Also r00st3r, how did you get this working with iphoto. When i open iphoto, it still opens mail.app

Be sure you change your iPhoto preferences so that the email client application is set to TB instead of mail.app.

sparrow_xiao
Feb 04, 2009, 07:22 PM
Hello grotsasha and others

I have seen this thread carefully,and tried the command line under the Terminal on Mac os x .The script has worked so good in English,but when i set a Japanese file to the 'attachment',the TB can't work well.

for example the following is the command line which I used:/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose "attachment='file:///にほん.png'"

Do you know the reseaon of my unsuccess?:confused: