Go Back   The macosxhints Forums > OS X Help Requests > Applications



Reply
 
Thread Tools Rate Thread Display Modes
Old 04-15-2008, 09:57 PM   #1
Hendel
Prospect
 
Join Date: Apr 2008
Posts: 5
Mail.app AppleScript

I'd been searching for a way to import/export my collection of 350 (and growing) signatures in and out of Mail.app. I finally found a set of AppleScripts here (specifically the last two at the bottom of the thread):

http://www.macosxhints.com/article.p...21103060644193

The export script works fine, creating a text file with all of my signatures. The import script doesn't - I've tried doing some troubleshooting by stripping it down to just this:

set sigText to "Test"
set signame to "Test"
tell application "Mail"
make new signature with properties {name:signame as text, content:sigText}
end tell

The script runs, outputting this to the Result window:

signature "Test" of application "Mail"

If I then go to the Mail.app Preferences/Signatures, I can see a new "Test" signature in the "All Signatures" list, and the total number of signatures has incremented by one. However, the Preferences window seems to freeze at that point - all clicks within it are ignored. If I Quit out of Mail.app and restart, the "Test" signature is gone (the total count has also dropped back down by one).

Is this a problem with the current version of Mail.app (the original thread with these scripts is several years old)? Is there another/better way to do this? Seems like this should be such a simple task. I'm a complete AppleScript newbie. Help?
Hendel is offline   Reply With Quote
Old 04-16-2008, 04:58 PM   #2
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,263
this has been a long-standing issue with Mail (at least a year old...). let me play with it a bit and see if there's a workaround.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 04-16-2008, 05:16 PM   #3
Hendel
Prospect
 
Join Date: Apr 2008
Posts: 5
Thanks - as a switcher (almost two years now), I'm pretty happy with Mail but can't believe there doesn't seem to be any signature management software apart from what's offered in the Preferences.
Hendel is offline   Reply With Quote
Old 04-16-2008, 05:33 PM   #4
Mikey-San
Hall of Famer
 
Join Date: Jan 2002
Posts: 3,541
Signatures, at least in Leopard's Mail.app, are stored .webarchive files inside the ~/Library/Mail/Signatures folder. They're not straight text files, but they can be opened in Safari. You could script Safari to open them, ask Safari for the document text, and then do with that text what you wish.
__________________
COMPUTER TYPE
SOME SPECIFICATIONS I COPIED FROM THE BOX
STUFF I INSTALLED ALL BY MYSELF
"WITTY QUOTE"
Mikey-San is offline   Reply With Quote
Old 04-16-2008, 06:55 PM   #5
Hendel
Prospect
 
Join Date: Apr 2008
Posts: 5
You're right, I can open the individual signature files in Safari - but my problem isn't *exporting* the signatures (the script I'd found for that works fine), it's *importing* new ones. Scripting through Safari still might work, I suppose, but does anyone have any idea how the naming scheme for the individual .webarchive signature files works (if it matters), or how to update Mail's index (assuming it keeps one)?
Hendel is offline   Reply With Quote
Old 04-16-2008, 08:37 PM   #6
tw
Hall of Famer
 
Join Date: Apr 2007
Posts: 4,263
you can actually use TextEdit to make webarchive files, so it might be possible to create all your signatures by scripting that. but then you'd have to monkey with the UUIDs and such in the signature plist file. it might be just easier to GUI script Mail.
__________________
Philosophy is a battle against the bewitchment of our intelligence by means of language. -LW-
tw is offline   Reply With Quote
Old 04-17-2008, 01:28 AM   #7
Mikey-San
Hall of Famer
 
Join Date: Jan 2002
Posts: 3,541
Oh, d'oh. I missed the "import" concept somehow. I suck at the forums today.

Agreed with tw here. I usually avoid GUI scripting like NYC subway rats, but it may be the easiest solution overall.
__________________
COMPUTER TYPE
SOME SPECIFICATIONS I COPIED FROM THE BOX
STUFF I INSTALLED ALL BY MYSELF
"WITTY QUOTE"
Mikey-San is offline   Reply With Quote
Old 04-17-2008, 02:22 AM   #8
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
Well I can help converting the Text or rtf file into webarchives.

Convert from rtf ( or you can change to txt )
Code:
tell application "Finder"
	
	set sourcePath to (choose folder with prompt "Please select the source directory")
	set sig_webAs to (items of folder sourcePath whose name extension is "rtf") as alias list
	
end tell
repeat with i from 1 to number of items in sig_webAs
	
	set this_item to POSIX path of item i of sig_webAs
	tell application "System Events"
		
		set sig_xml to do shell script "Textutil   -convert webarchive " & quoted form of this_item
		log sig_xml
		
	end tell
	
end repeat

Convert from webarchive to rtf or ....

Code:
tell application "Finder"
	
	set sourcePath to "Macintosh HD:Users:UserName:Library:Mail:Signatures" as alias
	set sig_webAs to (items of folder sourcePath whose name extension is "webarchive") as alias list
	
end tell
repeat with i from 1 to number of items in sig_webAs
	
	set this_item to POSIX path of item i of sig_webAs
	tell application "System Events"
		
		set sig_xml to do shell script "Textutil   -convert rtf " & quoted form of this_item
		log sig_xml
		
	end tell
	
end repeat
With these examples, Textutil will create the new file in the same directory as the orig. But if you look at the Man page you can see how to change that.

Also I have not had time to test the import, but you should note the is a "SignaturesByAccount.plist" file that may also need updating
__________________
MH.
mark hunte is offline   Reply With Quote
Old 04-23-2008, 12:52 PM   #9
mark hunte
MVP
 
Join Date: Apr 2004
Location: Hello London Calling
Posts: 1,787
For future reference,

I have a posted a hint on the main site, which takes the idea in my last post to
the next step, of actually fully importing/exporting your Rtf files (or other formats), Straight into/out of the Mail.app Signatures.

Another take on exporting and importing Mail signatures
__________________
MH.
mark hunte is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 02:40 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.