Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create dynamic Mail signatures via fortune Apps
I love ending my emails with a witty saying or neato quote, so for the past year now, I've been composing my emails, then opening up a Terminal window and copy-pasting the output from fortune into the message before sending. There is a *much* better way of doing this, of course! Open up Script Editor and create this script (note you have to replace /path/to/fortune with the path to the fortune installation on your system):
tell application "Mail"
  activate
  make new outgoing message with properties ¨
   {content:do shell script "/path/to/fortune", visible:true}
end tell
Save this in ~/Library/Scripts/Mail Scripts (you may have to create this folder). Open up Mail and select 'Update Scripts Menu' from the Scripts menu (the AppleScript icon between 'Window' and 'Help'). Now select the name of the script you just created and boom! Fortuned email sigs!

If you want to take this one a step further, use MenuMaster, iKey, etc. and assign the script a key combination (such as Cmd-Opt-Shift-N, for instance).

[robg adds: If you use fink, you can install fortune by typing sudo apt-get install fortune-mod. If you do so, your path to fortune is /sw/bin/fortune. You can also assign a hot key by naming the script a certain way -- 'Fortune___ctl-cmd-f.scpt' for instance, will assign it Control-Command-F. This script creates a new mail message, so don't start typing one and then call the script; call the script first...]
    •    
  • Currently 3.83 / 5
  You rated: 4 / 5 (6 votes cast)
 
[14,612 views]  

Create dynamic Mail signatures via fortune | 24 comments | Create New Account
Click here to return to the 'Create dynamic Mail signatures via fortune' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
my fink doesn't find fortune
Authored by: andrew_zinn on May 06, '04 10:43:01AM

When I type "sudo apt-get install fortune-mod" this is what I get:
Password: <I enter my password>
Reading Package Lists... Done
Building Dependency Tree... Done
E: Couldn't find package fortune-mod

A simple "fink install fortune" gives me this:
sudo /sw/bin/fink install fortune
Information about 1116 packages read in 1 seconds.
Failed: no package found for specification 'fortune'!

Is there some parameter I need to change to tell fink where to find this package?



[ Reply to This | # ]
my fink doesn't find fortune
Authored by: maddys_daddy on May 06, '04 12:35:58PM

Try adding the -mod to the end:
sudo /sw/bin/fink install fortune-mod
I use fink commander, and the package is called fortune-mod.



[ Reply to This | # ]
my fink doesn't find fortune
Authored by: andrew_zinn on May 06, '04 12:41:37PM

Thanks. I'm not Unix-proficient, and I thought the -mod was a parameter. I got it now.



[ Reply to This | # ]
my fink doesn't find fortune
Authored by: JaxMyers on May 06, '04 03:56:42PM

what does that mod stand for?



[ Reply to This | # ]
my fink doesn't find fortune
Authored by: malvolio on May 06, '04 03:58:45PM

mod = "Message Of the Day"

---
/mal



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: mahakk on May 06, '04 12:16:37PM

you can assign sortcuts to scripts simply by adding

___ctl-M

(for example) to the end of the name (right before the extension).
the above addition will let you run the script by hitting ctrl-shift-M.



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: gdanko on May 06, '04 12:33:29PM

How about you write this script...

#!/bin/sh
/path/to/fortune | /bin/mail -s "Your subject here" recipient@domain.tld

Then cron it for whatever frequency you like... This will accomplish the same thing with no user intervention necessary. :)



[ Reply to This | # ]
Uh ... no
Authored by: Greedo on May 06, '04 01:46:20PM

That sends an email to whoever with a fortune at defined intervals.

I don't think the original poster wants to send random quotes to one person every 5 minutes. He wants to use a random quote as part of his signature.

See further down for another way of accomplishing this.



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: sal11215 on May 06, '04 12:36:01PM

I did this with Mac::Glue and have it set in cron:

#!/usr/local/bin/perl

use strict;
use Mac::Glue;

my $Mail = Mac::Glue->new('Mail');

LOOP: foreach my $oldsig ($Mail->prop('signatures')->get) {

if ($oldsig->prop('name')->get =~ /^mysig$/) {
$Mail->delete($oldsig);
last LOOP;
}

}

$Mail->make(new => signature => with_properties =>
{
name => "mysig",
content => "a call to fortune, uptime, et al would go here"
}
);



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: robhague on May 07, '04 09:26:54AM
I do the same thing with an AppleScript (but then I didn't know about Mac::Glue - I'll have to check that out). It's worth mentioning that I have the cron job check that Mail is running (using ps and grep) before launching the script. That way, if I'm not running Mail, it won't start up spontaneously every five minutes.

(Another nice feature about doing things this way is that you can have multiple signatures using multiple fortune files, and some that don't use Fortune at all. Handy if you don't want to accidentally send mail with quotes from comics to potential employers.)

[ Reply to This | # ]

Create dynamic Mail signatures via fortune
Authored by: af3556 on Sep 02, '04 10:12:29PM
Below is an extended version that a) tests to see if Mail is running before attempting the update, b) reads quotes from a .quotes file in your home directory (fortune can often be inappropriate), and c) prefixes the quote with a constant signature 'template' (i.e. your name + phone). Here's an example .quotes file:

Be alert. The world needs more lerts.
--
It's impossible to foresee the consequences of being clever.
--
Out of my Mind - Back in 5 Minutes
--
One person, one vote (may not apply in certain States).
--
chown -R us:us /yourbase
--
Blessed are we who can laugh at ourselves, for we shall never cease to
be amused.
--
If anyone's not used Mac::Glue before, here's what I did to fetch and install Mac::Glue via the CPAN (http://cpan.org), and configure for Mail:

$ sudo cpan Mac::Glue
$ sudo gluemac /Applications/Mail.app 
You might like to install this script in cron: (save code in a file, e.g. /Users/you/bin/mail_randomsig.pl)

$ chmod +x /Users/you/bin/mail_randomsig.pl
$ ( crontab -l; echo "20,50 * * * * @AppleNotOnBattery /usr/bin/nice /Users/you/bin/mail_randomsig.pl " ) | crontab -

The script:

#!/usr/bin/perl
# - reads a random quote from a quotes file (each quote is one or more lines
#   separated by '--' on a line by itself), and appends to a signature 
#   template, which is then installed as the RandomQuote in Mail.app
# - based on an original idea at macosxhints.com ("Create dynamic Mail 
#   signatures via fortune")
#
# - Mac::Glue incurs a significant startup CPU hit (~40% CPU for a bit over a 
#   second on a 867MHz PowerBook):
#   $ time bin/mail_randomsig.pl 
#   real    0m1.491s
#   user    0m0.410s
#   sys     0m0.130s
# - I considered running as a daemon to mitigate this startup overhead; 
#   though as the perl+Mac::Glue memory footprint is around 12 MB real 
#   I decided to leave as a 'niced' cron job (perl alone is ~1MB real)
# - crontab (at 20 past and 10 to the hour):
#   20,50 * * * * @AppleNotOnBattery /usr/bin/nice /Users/ben/bin/mail_randomsig.pl 
#
# - for resource comparison I wrote an equivalent AppleScript 'stay-open' 
#   application (omitting actually reading the quotes file); the AS app 
#   uses 13.9MB real mem
# - i.e. perl+Mac::Glue's overhead is about the same as AS

use strict;
use Mac::Glue;

use Mac::Apps::Launch qw(IsRunning);

use constant SIGSRC => "$ENV{HOME}/.signature.src";
use constant QUOTES => "$ENV{HOME}/.quotes";

use constant SIGNAME => 'RandomQuote';

# had to run 'sudo gluemac /Applications/Mail.app' to set up the event 'glue'
# (don't know if full path is required)

# this takes about 1.2s on a PowerBook G4/867 (10.3.4)
my $Mail = Mac::Glue->new('Mail');

my $sig;

unless (IsRunning($Mail->{ID}))
{
    exit;
}

foreach my $sig ($Mail->prop('signatures')->get)
{
  if ($sig->prop('name')->get eq SIGNAME)
  {
    $Mail->delete($sig);
    last;
  }
}

# read signature "template", append randomly selected quote
open FH, SIGSRC or die "failed to open [" . SIGSRC . "]: $!\n";
$sig = join '', <FH>;
close FH;

open FH, QUOTES or die "failed to open [" . QUOTES . "]: $!\n";
{
  $/="\n--\n";
  my $l;
  while (<FH>) { rand($.) < 1 && ($l = $_) }
  chomp $l;
  $sig .= $l;
}
close FH;

#warn "[$sig]\n";

$Mail->make(new => signature => with_properties =>
  {
    name => SIGNAME, content => $sig
  }
);



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: XDave on May 06, '04 03:07:35PM

This is quite a neat hint. Can anyone help me with how I can display the Fortune quote in a different colored text?



[ Reply to This | # ]
Chaning the font/color
Authored by: inspired_tmu on May 07, '04 06:13:41PM

Check out the source for the Crazy Message Text script (located in /Library/Scripts/Mail\ Scripts).



[ Reply to This | # ]
Chaning the font/color
Authored by: XDave on May 08, '04 12:51:29PM

Thanks for responding to my question, however after viewing that script I'm still very confused about how to do this. Just wanting to select a different color and I am not AppleScript savvy to the extent that I can identify and pull out the part or parts of that script that may allow me to accomplish the desired result. More specific assistance would be helpful and very much appreciated.



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: scdown on May 06, '04 03:33:15PM
You could also use a slightly different script to put the fortune at the beginning of the outgoing message window (I'm using my own fortune database in this example) - you could then use the script in replies/forwards/redirects...

tell application "Mail"
	activate
	get do shell script "/sw/bin/fortune jackhandy"
	copy return & return & ¨
          "-----------------------------------" & return & ¨
          the result & return & return ¨
          to theFortune
	get content of first outgoing message
	copy theFortune & the result to ¨
          content of first outgoing message
end tell


[ Reply to This | # ]
More on dynamic signatures
Authored by: swedentom on May 07, '04 01:48:07PM
You might want to check out MailTunes.

[ Reply to This | # ]
More on dynamic signatures
Authored by: Orj on May 15, '08 03:40:34AM

Well, MailTunes is apparently no longer supported, and freezes the Signature Preferences window (at least with Mail Version 3.2 (919/919.2)).

All Applescript suggestions in this thread fail on the Braindamaged outgoing message Mail/AppleScript bug described in Apple Discussions.

---
In theory, theory and practice are the same. In practice, they're not.

[ Reply to This | # ]

Place text above Fortune Signature ...
Authored by: keyizm on May 09, '04 05:08:50PM

does anyone know how to modify the original posted script to include text above the inserted Fortune quote? I'd like it to look something like this:

************************************************************
Name
E-mail: xxx
AIM: xxx
MSN: xxx
Yahoo: xxx

Quote:
The sooner you make your first 5000 mistakes, the sooner you will be
able to correct them.
-- Nicolaides

i'm not AppleScript savvy so any help would be greatly appreciated, thanks!



[ Reply to This | # ]
Place text above Fortune Signature ...
Authored by: jms1 on May 09, '04 06:02:00PM
create a shell script like so...
#!/bin/sh

echo <<EOF
========
Name: xxxxx
ICQ: xxxxx
...
EOF

/sw/bin/fortune
make the shell script executable (using "chmod 700 xxx") and change the original applescript to call this shell script instead of calling /sw/bin/fortune directly.

[ Reply to This | # ]
Place text above Fortune Signature ...
Authored by: keyizm on May 10, '04 02:52:32AM

thanks for the advice! for some reason i couldn't get your script to work but i modified it slightly and i was able to get this version to work:

#!/bin/sh

echo "
************************************************************
Jon Doe
E-mail: xxx
AIM: xxx
MSN: xxx
Yahoo: xxx

Quote:"

/sw/bin/fortune



[ Reply to This | # ]
Place text above Fortune Signature ...
Authored by: GlowingApple on Mar 15, '06 11:41:31AM

I believe the previous script needs to have 'cat' insted of 'echo', though your method works equally well :)

---
Jayson --When Microsoft asks you, "Where do you want to go today?" tell them "Apple."



[ Reply to This | # ]
Create dynamic Mail signatures via fortune
Authored by: lonney on Sep 17, '04 03:05:36PM

This is pretty cool, found it when looking for the fortune program to install and add to my .profile

Is there any way have the script run when you start a new message by pressing "New" ??



[ Reply to This | # ]
Fortune? Bah
Authored by: Shiver758 on Sep 17, '04 10:27:12PM
How very 1988.

How about something a bit more fun (not to mention up-to-date)?

I discovered my new favorite site this week, and it immediately sprang to mind when I read this. Fortune is just so.. tired.

Firstly, check out http://www.thesimpsonsquotes.com. Then, check out http://www.thesimpsonsquotes.com/add_random_quotes.html. After checking that the code provided on the site offers you a handy GET var to change the number of quotes that come back, my mind immediately started cranking.. So, I used a bit of curl/perl to create myself a random password generator for my Samba PDC.. But, I digress. Using a bit of that perl code, I've modded this hint to make it do random SIMPSONS quotes, instead of used up old bloody Fortune quotes. Be the first kid on your block to have random Simpsons .sigs!!

First, the perl:

#!/usr/bin/perl
open (PIPE, "curl http://www.thesimpsonsquotes.com/random.php?num=1 2> /dev/null |");
@myData = <PIPE>;
close(PIPE);

foreach $line (@myData) {
  if($line =~ s/^<p>//g) {
    $line =~ s/....$//g;
    if(!@ARGV[0] || @ARGV[0] != '--with-name') {
      $line =~ s/[^:]+://g;
    }
    chomp $line;
    print "---\n";
    print $line."\n";
    exit 0;
  }
}
Save this as /Users/username/bin/simpson_quote.pl

Back out to the shell and run
 chmod +x ~/bin/simpson_quote.pl 
(make the perl script an executable).

Then, follow the normal instructions from the hint (and the comments, if you like, a big thank you to the person who submitted the ___m thing.. badass!). Just substitute
 <path to fortune> 
with
 /Users/<username>/bin/simpson_quote.pl --with-name 
(the --with-name bit is optional.. it just leaves in the starting bit with Character Name: rather than leaving it off)

I just set it up myself, and hopefully I've actually written the instructions correctly.. I'll check back here for questions, comments.

Have fun! And remember...

---
Milhouse: Why do you have a social worker? I am the one with stigmata.

PS - Cheers to the original author. Handy little AScript. ;)

[ Reply to This | # ]
Fortune? Bah (oops!)
Authored by: Shiver758 on Sep 18, '04 12:05:17AM

BTW, I found a little problem. Some of the quotes have a trailing "<br>". So, to protect from this I changed line 12 to read:

$line =~ s/<br//g;

I had it in the full version, just didn't copy it over into the snippet I put on here.

Have fun!



[ Reply to This | # ]