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

Another take on exporting and importing Mail signatures Apps
It seems that there were some problems with older hints to import and export signatures to and from Mail.app. In response to this Macosxhints forum question, I wrote some scripts to help with the process.

Since Mail.app uses .webarchive files (stored in your user's Library » Mail » Signatures folder), the scripts use the command line tool textutil to do the conversion from RTF to webarchive. textutil can convert to and from other formats you may want to use as well: txt, html, rtf, rtfd, doc, docx, wordml, odt, or webarchive.

Import_Mail_Signatures Script -- View the script's source

This script will allow you to choose a folder of RTF files, convert them into the new webarchive files, and place them into the Mail.app signature folder as described above. It will also write the details of the new files to the SignaturesByAccount.plist (also in the Signatures folder). I would suggest you quit Mail.app first before running the script. But if you don't, you can quit Mail.app after you run the script, then reopen Mail, and Mail.app will read the modified plist file.

I have only set the script to put the new Signatures into the All Signatures preference (in Mail.app's Signature preferences). All you have to then do is drag any of the signatures onto an account name as normal within the Signature preferences. You can remove them if you wish, using the options to delete in the same Signature preferences panel.

Export_Mail_Signatures Script -- View the script's source

This script will match the Signatures found in the AllSignaturesKey array of the SignaturesByAccount.plist file with the webarchive files found in the Mail/Signatures folder. Any Signatures found in the AllSignaturesKey array will only be processed if a webarchive file is found for it.

This script will then convert those matching signatures into new RTF files and place them into a folder of your choice, naming them as the signatures are named in Mail.app.

Extra Script
This script is just to show you how you can use textutil with Applescript to convert to and from any of the supported formats of your choice. [robg adds: I haven't tested these scripts, but others have, and I've been told they work fine.]
    •    
  • Currently 1.78 / 5
  You rated: 2 / 5 (9 votes cast)
 
[11,796 views]  

Another take on exporting and importing Mail signatures | 2 comments | Create New Account
Click here to return to the 'Another take on exporting and importing Mail signatures' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another take on exporting and importing Mail signatures
Authored by: broz on May 27, '08 02:02:46PM

These scripts are pretty cool! Very useful to me. Adding a new signature directly in Mail, with AppleScript, caused me problems with the signature dialog locking up.

Now I think I'll "borrow" some of the code from these scripts to create a signature from the clipboard. I often find quotes that I want to use in a mail signature, and a script that worked with the clipboard would make that very easy.

THANKS for giving me something to work with!



[ Reply to This | # ]
Another take on exporting and importing Mail signatures
Authored by: mark hunte on Feb 12, '09 02:03:25AM
Dave Hughes Pointed out that the random file name generator in the Import
script did not have an if exists check.
The New script below now includes this.
Thanks Dave.

MH

(* // Import_Mail_Signatures  Script//
Created by mark hunte on 19/04/2008.
//  Copyright 2008 . All rights reserved. ( well you know what I mean)
In response to Macosxhints  question in http://forums.macosxhints.com/showthread.php?p=464704-

*****  WARNINGS  >
Although I have not had any issues with this script,  It goes without saying...

** YOU use this script at you own risk, and should back up any files you feel is necessary in case of some unforseen problem **

If you Pass this script on Modified or whole, Please include all comments and warnings.

****<

This script will allow you to choose a folder of rtf files, and them into New webarchive files , Place them into 
the mail.app signature folder ("/Users/Username/library/Mail/Signatures/").

And write the details of the new files to the SignaturesByAccount.plist
also in the Signatures folder. 

 The script use the command line tool Textutil to do the conversion from RTF to webarchive. 
Textutil can convert to and from other formats  you may want.
-- formats --( txt, html, rtf, rtfd, doc, docx, wordml, odt, or webarchive )
--
I would suggest you quit Mail.app  first before running.
But if not, Once run, you can quit Mail.app and reopen it, for mail.app to read the plist file again.


I have only set the Script to  put the new Signatures into the ALL Signatures preference (in Mail.app's Signature preferences.)
All you have to then do is drag any of the signatures on to an Account name as normal within the Signature preferences.

And remove them if you wish, using the options to delete in the same Signature preferences
--


*)
global uniqPath, uniq
tell application "Finder"
	(* set format of source files *)
	set format_ to "rtf"
	(* choose Source for rtf files*)
	set sourcePath to (choose folder with prompt "Please select the source directory")
	(* only allow rtf files*)
	set sig_webAs to (items of folder sourcePath whose name extension is format_) as alias list
	(* get users Mail signature folder*)
	tell application "System Events" to set sigPath to POSIX path of (path to home folder of user domain) & "/library/Mail/Signatures/" as Unicode text
end tell

(* repeat for each rtf file found*)
repeat with i from 1 to number of items in sig_webAs
	(* get name of rtf file minus  extension*)
	tell application "Finder" to set SignatureName to text from word 1 to word -2 of (displayed name of (item i of sig_webAs) as string)
	(* get the posix path (unix) of the file *)
	set this_item to POSIX path of item i of sig_webAs
	(* create a unique name for the  web archive *)
	
	my Rand(sigPath)
	--set uniq to (randomString(8) & "-" & randomString(4) & "-" & randomString(4) & "-" & randomString(4) & "-" & randomString(12))
	--set uniqPath to (sigPath & uniq & ".webarchive")
	
	(* convert the rtf file to a  web archive, saving it to the Mail signature folder and naming it with the unique name  *)
	set sig_xml to do shell script "Textutil   -convert webarchive " & quoted form of this_item & " -output " & quoted form of uniqPath
	log sig_xml
	(* go to handler,  writePlist(uniq, SignatureName, sigPath) *)
	my writePlist(uniq, SignatureName, sigPath)
end repeat
on Rand(sigPath)
	set checkResult to true
	repeat until checkResult is false
		set uniq to (my randomString(8) & "-" & my randomString(4) & "-" & my randomString(4) & "-" & my randomString(4) & "-" & my randomString(12))
		set uniqPath to (sigPath & uniq & ".webarchive")
		tell application "Finder"
			if not (exists file (uniq & ".webarchive" as string) of (POSIX file sigPath as alias)) then
				set checkResult to false
			else
				set checkResult to true
				
				log uniq
			end if
		end tell
	end repeat
end Rand
(* handler to write to the  SignaturesByAccount.plist, adding the new details of the new file to the "AllSignaturesKey" array *)
on writePlist(uniq, SignatureName, sigPath)
	tell application "System Events"
		
		set SignatureIsRichSTATE to "true"
		
		
		set this_plistfile to (sigPath & "SignaturesByAccount")
		(* escape any spaces in name of file *)
		set SignatureName to (do shell script "echo " & quoted form of SignatureName & "|sed 's/\\ /\\\\ /g'")
		(* write to the  SignaturesByAccount.plist *)
		do shell script "defaults  write " & this_plistfile & " \"AllSignaturesKey\" -array-add '<dict><key>SignatureIsRich</key><" & SignatureIsRichSTATE & "/><key>SignatureName</key><string> '" & SignatureName & "'</string><key>SignatureUniqueId</key><string>" & uniq & "</string></dict>'"
		
	end tell
end writePlist

(* handler to  create a unique name for the new signature web archive file *)
on randomString(aLength)
	set aLength to aLength / 2 as integer
	log aLength
	set randNumber to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
	set randomChars to {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
	set aString to ""
	
	repeat aLength times
		set aString to aString & some item of randNumber & some item of randomChars
	end repeat
	
	return aString
end randomString

---
mh

[ Reply to This | # ]