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


Click here to return to the 'Export Mail signatures to a text file' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Export Mail signatures to a text file
Authored by: ces3001 on Nov 19, '03 10:00:21PM
Based on these, Here are two companion scripts (to be placed in ~/Library -> Scripts -> Mail Scripts) that do the exporting and importing. These scripts preserve the titles for the signatures. For the importing script, you are given the option of deleting the current signatures in Mail before importing (so you can add signatures by adding them to the text file). Note you can set strings that should go before and after each signature, so that the signature text file is clear of them. I like to have a -- (linebreak) before each sig.

EXPORT script


property textBeforeSig : "--
"
property textAfterSig : ""

on remove_before_and_after(sig)
	set str to sig
	set len to number of characters in str
	set bef_num to number of characters in textBeforeSig
	set aft_num to number of characters in textAfterSig
	if (aft_num > 0) and ((characters (len - aft_num + 1) thru len of str) as string = textAfterSig) then
		set str to (characters 1 thru (len - aft_num) of str) as string
	end if
	if (bef_num > 0) and ((characters 1 thru bef_num of str) as string = textBeforeSig) then
		set str to (characters (bef_num + 1) thru len of str) as string
	end if
	return str
end remove_before_and_after

set sigdump to choose file name with prompt "Export signatures to:" default name "Signatures.txt"
do shell script "touch " & (quoted form of POSIX path of sigdump)
set sigdump to sigdump as alias
set theFile to open for access (sigdump) with write permission
set eof theFile to (get eof theFile)
tell application "Mail"
	set sigcount to count of signatures
end tell
repeat with i from 1 to sigcount
	tell application "Mail"
		set signame to name of signature i
		set sigcontent to content of signature i
	end tell
	set sigcontent to remove_before_and_after(sigcontent)
	if i > 1 then
		write "%%" & return to theFile as string
	end if
	write signame & return & sigcontent & return to theFile as string
end repeat
write "%%" & return to theFile as string
close access (sigdump)
IMPORT script

(* Signature File format should be (text file, use Macintosh carriage returns):
signature 1 title
signature 1 contents (text only)
&&
signature 2 title
signature 2 contents
%%
etc
*)

-- set these two string to whatever you want to have before and after each sig. Include carriage returns, if you need them.
property textBeforeSig : "--
"
property textAfterSig : ""

-- no user modification below this line
--property sigdump : (path to desktop as string) & "signatures.txt"
set sigdump to choose file
set sigdump to sigdump as alias
set theFile to open for access (sigdump)
set theText to read theFile using delimiter return
close access theFile

set sigNumber to 0
set sigText to ""
set signame to ""

display dialog "Remove existing signatures from Mail before importing?" buttons {"Yes", "No"}
if the button returned of the result is "Yes" then
	tell application "Mail"
		set sigcount to count of signatures
	end tell
	repeat with i from 1 to sigcount
		tell application "Mail"
			delete signature 1
		end tell
	end repeat
end if

repeat with i from 1 to count of theText
	set theLine to item i of theText
	if theLine is "%%" then
		set sigText to sigText & textAfterSig
		tell application "Mail"
			make new signature with properties {name:signame as text, content:sigText}
		end tell
		set sigNumber to sigNumber + 1
		set sigText to ""
		set signame to ""
	else if signame = "" then
		set signame to theLine
	else if sigText = "" then
		set sigText to textBeforeSig & theLine
	else
		set sigText to sigText & "
 " & theLine
	end if
end repeat
-- add the last text if there is any (i.e. File doesn't terminate with %%)
if not (sigText = "") then
	set sigText to sigText & textAfterSig
	tell application "Mail"
		make new signature with properties {name:signame as text, content:sigText}
	end tell
end if


[ Reply to This | # ]
A Plain Text file from TextEdit isn't a Text Only file from MS Word X
Authored by: milo on May 07, '04 03:46:04PM

I spent almost two days trying to get the Import script to work with my text file, not the text file generated with the Export script.

Saving my file with TextEdit, either RTF or Plain Text, would not work.

When I tried to save the files with MS Word X, Text Only, it worked GREAT!

Just when you think a Mac "return" key is generic, and works the same in all apps...

Signed,
A tired old (veteran) computer teacher!



[ Reply to This | # ]