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

Export Mail signatures to a text file Apps
A friend of mine wanted to export signatures from Mail to a text file. Signatures are kept in a plist file, but are stored in a RTF format that doesn't lend itself to easy exporting.

Using a little bit of AppleScript knowledge, I constructed the following script that exports each signature to a text file:
do shell script "touch ~/Desktop/sigdump.txt"
property sigdump : (path to desktop as string) & "sigdump.txt"
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
write "Signature " & i & "
" & signame & "
" & sigcontent & "
" to theFile as string
end repeat
close access (sigdump)
Enter the script using Apple's ScriptEditor, and note that the "write" portion of the script cotains three quoted line breaks (hence the lack of indentation on those lines).
    •    
  • Currently 1.00 / 5
  You rated: 1 / 5 (1 vote cast)
 
[10,513 views]  

Export Mail signatures to a text file | 8 comments | Create New Account
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.
Small problems
Authored by: Reddog on Nov 03, '02 08:10:35PM

I had two problems: the script stopped until I created a text file named sigdump on the desktop, and the script stopped again when it encountered a signature that has a small graphic in it. I don't know what I can do to work around that.

Pat



[ Reply to This | # ]
Small problems
Authored by: THEM on Nov 03, '02 11:10:25PM

It shouldn't stall because the first line creates the file it needs, and I'd imagine it would fail if it couldn't find touch.

It's fail on images since it's writing a text file, and I didn't know signatures could contain images.



[ Reply to This | # ]
Small problems
Authored by: mkennard20 on Nov 05, '02 03:08:34PM

I would love to be able to add images, well one for a client with a logo.



[ Reply to This | # ]
Export Mail signatures to a text file
Authored by: wannesdaemen on Mar 28, '03 09:37:36AM
that's great!
er, i am a complete applescript newbie -
is there a way to do this proces in reverse?
in other words: is it possible to make changes to all of my signatures at the same time?
i have a lot (40something), they're all different, but each has a similar part that i wish to change from time to time. can i do this in some global manner?

[ Reply to This | # ]
Import Mail signatures from a text file
Authored by: EvanRobinson on Jun 06, '03 10:43:05AM
-- this script will import signatures from "sigdata.txt"
-- on your desktop.
-- each signature is multiple lines, separated by a single
-- line consisting solely of two percent signs '%%'
-- for background on why I wrote it, see
-- http://www.enginesofmischief.com/blogs/ramblings/archives/000096.php
-- where there will also be an expanded version someday

property sigdump : (path to desktop as string) & "sigdata.txt"

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 ""
repeat with i from 1 to count of theText
        set theLine to item i of theText
        if theLine is "%%" then
                tell application "Mail"
                        make new signature with properties {name:sigNumber as text, content:sigText}
                end tell
                set sigNumber to sigNumber + 1
                set sigText to ""
        else if sigText = "" then
                set sigText to theLine
        else
                set sigText to sigText & "
 " & theLine
        end if
end repeat


[ Reply to This | # ]
Import Mail signatures from a text file
Authored by: EvanRobinson on Jun 09, '03 03:34:16PM
The expanded version is now at my web page.

[ Reply to This | # ]
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 | # ]