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

A real random fortune signature for Mail.app Apps
Okay, I've read all of the hints about random signatures in Mail.app (like this one), and wasn't happy with any of them. What I want is something that generates new signatures every so often (preferably every time a new message is created, but every minute or five will do, if it doesn't chew too much CPU). So, I came up with the following AppleScript:
set fortune to do shell script "/path/to/fortune"
tell application "Mail"
  set content of signatures to "-- 
Real Name <email@domain.net>

" & fortune
end tell
This can be run from the Scripts menu (Save to ~/Library/Scripts/Mail), or saved as an application and run from the Finder, or put it in your crontab (Get Cronnix!). This works if you only have one signature -- someone else may care to improve it for multiple signatures. Maybe even create a fortune'd signature for every account, with the name and address grabbed from the account. Now that might be cool.

[robg adds: As noted in the linked hint, you'll have to install fortune yourself.]
    •    
  • Currently 3.17 / 5
  You rated: 1 / 5 (6 votes cast)
 
[14,128 views]  

A real random fortune signature for Mail.app | 19 comments | Create New Account
Click here to return to the 'A real random fortune signature for Mail.app' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A real random fortune signature for Mail.app
Authored by: valx on May 25, '04 01:55:06PM

Instead of doing a command line install of Fortune, you could download Cocoa Fortune. Then run the shell script as:

cd "/Applications/Cocoa Fortune/Cocoa Fortune.app/Contents/MacOS";./fortune;

That way fortune is all wrapped up in a nice little package (that contains a GUI too), and there's no need to go to the command line if you don't want to.



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: cudaboy_71 on May 25, '04 02:42:10PM

for we of the GUI, please elaborate.

cd "/Applications/Cocoa Fortune/Cocoa Fortune.app/Contents/MacOS";./fortune;

does not compile as applescript. what do we do with it?

---
if it aint broke, break it!



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: Cap'n Hector on May 25, '04 03:14:00PM
Change the code of the given AppleScript to: set fortune to do shell script "cd "/Applications/Cocoa Fortune/Cocoa Fortune.app/Contents/MacOS" ; ./fortune;" tell application "Mail" set content of signatures to "-- Real Name " & fortune end tell

[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: Cap'n Hector on May 25, '04 03:17:30PM
Blah, I forgot that I need to include formatting:

set fortune to do shell script "t "cd "/Applications/Cocoa Fortune/Cocoa Fortune.app/Contents/MacOS" ; ./fortune;"
tell application "Mail"
set content of signatures to "--
Real Name

" & fortune
end tell


[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: cudaboy_71 on May 25, '04 04:53:02PM

looks like applescript...but, doesnt compile :(

error: A identifier can't go after this """. goes back to the script with the "cd highlighted.

---
if it aint broke, break it!



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: valx on May 25, '04 05:45:57PM

When using quotation marks in the do shell script command of applescript, you have to escape them with a \.

So it should be:

set fortune to do shell script "cd \"/Applications/Cocoa Fortune/Cocoa Fortune.app/Contents/MacOS\" ; ./fortune;"

[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: valx on May 25, '04 05:50:01PM

Oops, have to escape them with

\
So your code will look like this:
set fortune to do shell script  "cd \"/Applications/Cocoa Fortune/Cocoa Fortune.app/Contents/MacOS\" ; ./fortune;"


[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: greed on May 26, '04 10:26:59AM

And how about changing that ';' to an '&&', so if the CD fails (because the program is gone or something), the 'fortune' command isn't attempted? So you get:
cd somedir && ./command

And while we're at it, is it really necessary to do the 'cd' first? Just
somedir/command
works for all but the most badly-written of programs.



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: chmod007 on May 30, '04 11:58:12AM

As the developer of Cocoa Fortune, I do feel like I need to respond to that ;-). You did, after all, imply that my program was badly written.

The fortune binary used by Cocoa Fortune uses a relative path for the built-in fortunes. Therefore, it is necessary to set up the current directory properly (so that datfiles == ./datfiles). If you have a datfile directory in some other location, cd to that place first.

This was done in order to allow the user to move the application around without problems.

/ Regards, David Remahl



[ Reply to This | # ]
CLI Compilable Fortune for OS X
Authored by: jriskin on May 25, '04 06:07:08PM

I couldn't find an official source for Fortune. After much searching, I ran across this.

http://homepage.mac.com/slahteine

Direct link
http://homepage.mac.com/slahteine/.cv/slahteine/Public/fortune.tar.gz-link.gz

Compiles and installs perfect. (remove the extra .MAC gz-link from the file name).



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: taxi on May 26, '04 04:38:52AM

Okay, I've amost finished the multi-account version:

[code]
tell application "Mail"
set sigs to {}
repeat with each in every account
set fortune to do shell script "~/bin/fortune"
set realname to full name of each
set email to email addresses of each
set sig to "--
" & realname & " <" & email & ">
" & fortune
set sigs to sigs & sig
end repeat
--set content of signatures to sigs
end tell
[/code]

As you can see by my commented out line, I cannot figure out how to get Mail.app to accept the signatures back in.

At least this version gets the real name and email address!



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: DoctorJ on May 28, '04 02:30:38PM

So will this work if i only have 1 account, but use multiple signatures?

---

Using a rusty Amiga 4000T & a shiny Mac PowerBook G4



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: mrchaotica on May 28, '04 03:57:13AM

Hey, this is really cool! It might be nicer to use "fortune -s" so you don't get a big paragraph-long sig, though.

Also, I bet there's a way to get this to run every time you select "Compose New Message" - anybody know what it is?



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: erickaterman on May 29, '04 10:42:19AM

I agree--I actually use the -s flag in my script, which directly updates the ~/Library/Mail/Signatures.plist file every other minute so that the signature shows up in Mail as a bona fide sig; for example, I can make "dynamic signature" my default sig, and it shows up automatically in new messages as well as in the list of sigs menu list in new messages. The script that alters the .plist file is (necessarily) a little messy, but it gets the job done. The only downside is that Mail doesn't refresh its list of signatures when the plist file is changed--and, as far as I can tell, there's no way to do this through AS or bash--so if you leave Mail open, then your signature might not be current. Otherwise, you can just quit and restart Mail, which isn't a big deal. Here's an example of a signature (most of the other stuff is there "for fun" or "because I can" or what-have-you):

---------------------------------------------
[name, etc.]

past:
recent apps: Script Editor; iCal; Safari; Mail; iTunes
recent docs: [file 1], [file 2], [hee hee]

present:
UTC: Sat May 29 14:35:00 GMT 2004
listening to: Dakesh York "Beethoven's Moonlight Sonata" (4:27) from Masterworks Reworked: Remixes For A New Generation

future:
next class: *automata theory* (this Thursday at 10am in PAIĀ 3.14: with glen nuckolls)
next radio: *Like Biting Into a Fork* (next Tuesday at 5am in KVRX: summer stylin' on FM)
next sport: *squash club* (this morning in 55 minutes in rsc/gregory: come and learn how to play squash)

checkuary, n:
The thirteenth month of the year. Begins New Year's Day and ends
when a person stops absentmindedly writing the old year on his checks.



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: taxi on May 30, '04 02:30:47AM

Hmm, You could probably mod the script so it creates the right number of signatures. Unless you used different names or return addresses, I'm not sure why you'd want to.

I use two accounts (but don't really get email at one of them), and since I prefer my isp address rather than my work one, I set my email to be sent from that account, and reflect this in my signature.

I found it a little tricky to figure out how to get more items in a list - it wasn't nearly as 'natural' as python's lists.



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: Flem on Dec 16, '04 10:55:55PM
I had that script running, but when I put it into the crontab it kept launching mail every time it executed, so I added a shell script to check if mail was running. You'll have to merge this with the multi-signature code if you like, but for a single person this works fine:


if ((do shell script "ps -c -U yourusername | awk '/Mail/ {print $5}'") = "Mail") then
	set fortune to do shell script "/sw/bin/fortune"
	tell application "Mail"
		set content of signatures to "
----------
*** INSERT SIGNATURE HERE***

" & fortune
	end tell
end if


[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: dushu on Jan 30, '11 10:05:50PM

I've been using this hint for quite some time with a small twist, however after updating to 10.6.6, the following problem has starting occurring intermittently:

Fortune gets stuck in a loop and starts using 90-100% of CPU.

My setup is as follows:

1. Fortune downloaded from http://www.thinkyhead.com/fortune (the other links on this page are no longer working including cocoa fortune) and compiled using xtools
2. Rule setup in mail.app to run the random signature script whenever an email comes to a specified mail address
3. Random signature script as follows:
_________________________________
set fortune to do shell script "/usr/bin/fortune"
set sigg to "Dushyant Ahuja
" & fortune
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Signature"}
set the enabledNotificationsList to ¬
{"Signature"}
register as application ¬
"Random Sig" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"

notify with name ¬
"Signature" title ¬
"Mail Signature" description ¬
sigg application name "Random Sig"

end tell
tell application "Mail"
set content of signature 1 to sigg
end tell
______________________________________
I even tried to change the script to kill fortune after 1 sec - however no result:
-----------------
set fortune to do shell script "/usr/bin/fortune&"
set sigg to "Dushyant Ahuja
" & fortune
delay 1
try
do shell script "killall fortune"
end try
tell application "GrowlHelperApp"
-- Make a list of all the notification types
-- that this script will ever send:
set the allNotificationsList to ¬
{"Signature"}
set the enabledNotificationsList to ¬
{"Signature"}
register as application ¬
"Random Sig" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Script Editor"

notify with name ¬
"Signature" title ¬
"Mail Signature" description ¬
sigg application name "Random Sig"

end tell
tell application "Mail"
set content of signature 1 to sigg
end tell
------------------
Would appreciate if someone can help



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: dushu on Feb 02, '11 01:07:08PM

Finally resorted to installing macports to install fortune - this version seems to be compiled for Intel whereas the earlier one was compiled for PPC;
No problems till now - fingers crossed.



[ Reply to This | # ]
A real random fortune signature for Mail.app
Authored by: finferflu on Feb 29, '12 11:51:34AM
If you only want to change one specific signature (and not overwrite the existing ones), you can instead use this:
set fortune to do shell script "/path/to/fortune"
tell application "Mail"
	set content of signature "SIGNATURE NAME" to "-- 
YOUR SIGNATURE 

" & fortune
end tell
What I personally did was creating an empty signature in Mail and used that in the script.

[ Reply to This | # ]