Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 8, 2012, 02:30 PM   #1
jtbbrandt
macrumors newbie
 
Join Date: May 2012
Create Outlook 2011 HTML Signature using AppleScript

What I Would Like to Do Using AppleScript:

Create an email signature in Outlook 2011. Apparently with the most recent update to Microsoft Office 2011 they have included more compatibility with AppleScript.

For example I can create a signature by doing the following:
tell application "Microsoft Outlook"
make new signature with properties {name:strName, content:contentHTML}
end tell

Where strName of the signature in Outlook and contentHTML is the actual content of the HTML email signature. The hurdle I am trying to get over is to be able to have contentHTML be the actual content of the .html file that has my signature.

I don't want to have the html code as the variable but rather what the html content would look like in a browser. For a reference of what I am trying to do using AppleScript see here.

Any suggestions on how I may be able to accomplish this?
jtbbrandt is offline   0 Reply With Quote
Old May 8, 2012, 04:18 PM   #2
Red Menace
macrumors 6502
 
Join Date: May 2011
Location: Littleton, Colorado, USA
You can just read the contents of your file, for example

Code:
set contentHTML to (read (choose file))
The HTML code is what determines what it looks like in a browser (take a look at the signature template used in the article).
__________________
MacBook Pro / OS X Yosemite (10.10) / Xcode 6.1 / RubyMotion FTW
Red Menace is offline   0 Reply With Quote
Old May 9, 2012, 11:11 AM   #3
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Now when I run:

set contentHTML to (read ("Users:username: Desktop:file.html"))

tell application "Microsoft Outlook"
make new signature with properties {name:strName, content:contentHTML}
end tell


I get an AppleScript Error: Can't make "Users:username: Desktop:file.html" into type file.

This is the error log: error "Can’t make \"Users:username: Desktop:with-cell-num.html\" into type file." number -1700 from "Users:username: Desktop:with-cell-num.html" to file
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 12:01 PM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
The pathname is wrong.

When using colon-separated directories, the first element must be the disk name:
Code:
 "Macintosh HD:Users:username:Desktop:file.html".
And there shouldn't be a space before "Desktop".

And "username" should be your actual user name, just as "Macintosh HD" should be your actual disk name.
chown33 is offline   0 Reply With Quote
Old May 9, 2012, 12:17 PM   #5
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Quote:
Originally Posted by chown33 View Post
The pathname is wrong.

When using colon-separated directories, the first element must be the disk name:
Code:
 "Macintosh HD:Users:username:Desktop:file.html".
And there shouldn't be a space before "Desktop".

And "username" should be your actual user name, just as "Macintosh HD" should be your actual disk name.
I added " Macintosh_HD " and received the same error as before. Can't make "Macintosh_HD:Users:username: Desktop:file.html" into type file.

I put the space between the : and the D otherwise it looks like this = esktop
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 12:33 PM   #6
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Code:
set the_file to (path to desktop as text) & "file.html" as alias
set contentHTML to (read the_file as «class utf8»)
Attached Thumbnails
Click image for larger version

Name:	Picture 2.png
Views:	26
Size:	51.0 KB
ID:	339027  
kryten2 is offline   0 Reply With Quote
Old May 9, 2012, 12:45 PM   #7
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Quote:
Originally Posted by kryten2 View Post
Code:
set the_file to (path to desktop as text) & "file.html" as alias
set contentHTML to (read the_file as «class utf8»)
OK. Now my code looks like:

set contentHTML to ("Macintosh_HD:Users:username: Desktop:with-cell-num.html")
set contentHTML to (read {"Macintosh_HD:Users:username: Desktop:with-cell-num.html" as class, utf8})
tell application "Microsoft Outlook"
make new signature with properties {name:strName, content:contentHTML}
end tell

it compiles however, I receive this error when it runs: Can't make "Macintosh_HD:Users:username: Desktop:with-cell-num.html" into type class.
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 12:47 PM   #8
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by jtbbrandt View Post
I put the space between the : and the D otherwise it looks like this = esktop
Below the post-editing box, below the "Submit Reply" and "Preview Post" buttons, is an area title "Additional Options".
There should be a "Miscellaneous Options" box there with two checkboxes.
One of the checkboxes is "Disable smilies in text".

Or do as I did and use the CODE tags.
chown33 is offline   0 Reply With Quote
Old May 9, 2012, 01:01 PM   #9
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Code:
set contentHTML to ((path to desktop as text) & "with-cell-num.html") as alias
set contentHTML to (read contentHTML)
tell application "Microsoft Outlook"
	make new signature with properties {name:strName, content:contentHTML}
end tell
kryten2 is offline   0 Reply With Quote
Old May 9, 2012, 01:08 PM   #10
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Quote:
Originally Posted by kryten2 View Post
Code:
set contentHTML to ((path to desktop as text) & "with-cell-num.html") as alias
set contentHTML to (read contentHTML)
tell application "Microsoft Outlook"
	make new signature with properties {name:strName, content:contentHTML}
end tell
That works!!! However, and this is curious to me, if I use name:strName it tells me that the variable strName is not defined. I didn't think this was a variable but rather a property.

Also, if I change name:strName to name:name for example the script runs and creates a signature in Outlook with the name Microsoft Outlook. If I use anything but name as the property I receive that variable not defined error. Any idea why it would do this?
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 01:31 PM   #11
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
From the System Events dictionary :
Quote:
make v : Make a new object.
make
new type : The class of the new object.
[at location specifier] : The location at which to insert the object.
[with data any] : The initial data for the object.
[with properties record] : The initial values for properties of the object.
→ specifier
You're telling "Microsoft Outlook" to do something but name is also a property of application and reserved. If you want to use the strName variable you should assign it a value. Like :

Code:
set strName to "John Doe"
or without the strName variable :

Code:
make new signature with properties {name:"John Doe", content:contentHTML}
kryten2 is offline   0 Reply With Quote
Old May 9, 2012, 03:24 PM   #12
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Thanks for all of your help. This was the part I was most worried about; getting the signature into Outlook.

Now that that is done I need to focus on actually creating the signature. I created a bash script to get that done but I am wondering that if I do it in applescript that I can get this whole process to be really smooth.

Here is my bash script:

Quote:
#this function prompts the user for their info
info (){
echo "What is your first and last name? ie: John Doe";
read fullName;
echo "What is your job title? ie: Corporate Wizard";
read jobTitle;
echo "What is your desk phone number? ie: xxx.xxx.xxxx"
read desk;
echo "What is your cell phone number? ie: xxx.xxx.xxxx";
read cell;
}
#this function prints the info the user inputted
verify (){
echo "This info will be shown in your email signature:"
echo -e "\tFullname:\t$fullName"
echo -e "\tJob Title:\t$jobTitle"
echo -e "\tDesk #:\t$desk"
echo -e "\tCell #:\t$cell"
}
#this function asks the user if they would like to go back and correct a mistake or continue
back () {
echo "Do you need to go back and correct a mistake? Type 'yes' to go back. Press any key to continue."
read answer
}

#begin script

info
verify
back

if [[ $answer = yes ]]; then
#statements
info
verify
back
else
sed -e "s/fullName/$fullName/" -e "s/jobTitle/$jobTitle/" -e "s/desk/$desk/" -e "s/cel/$cell/" with-cell-num.html > ~/Desktop/domo.html
fi
echo "Your signature has been created as 'newSignature.html' file on your desktop."
This script basically asks the user for input, stores that input as a variable and then finds in the template email signature file for the certain places to put the variables. Then it creates a new file.

Is there a way to do a similar thing using applescript? Especially the sed part.
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 04:48 PM   #13
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Quote:
Is there a way to do a similar thing using applescript? Especially the sed part.
You can but there's no need to. Applescript can run shell scripts too.

From the Terminal Suite dictionary :

Quote:
do script v : Runs a UNIX shell script or command.
do script [text] : The command to execute.
[in tab, window, or any] : The tab in which to execute the command
→ tab : The tab the command was executed in.
Code:
set theScript to "/path/to/your/script"
tell application "Terminal"
	activate
	do script theScript in window 1
end tell
But if you really want to. You can accomplish something similar for your echo/read lines with :

Code:
set thefullName to text returned of (display dialog "" default answer "" buttons {"OK"} default button 1)
Sed line :

Code:
do shell script ""
Last echo line :

Code:
display dialog "" buttons {"OK"} default button 1

You might want to take a look at those dictionaries. All the info is there for you to use.
Also the last echo line in your script says Your signature has been created as 'newSignature.html' file on your desktop. Must be confusing for the user if they search for a nonexisting file. Shouldn't that be domo.html?

Last edited by kryten2; May 9, 2012 at 05:17 PM.
kryten2 is offline   0 Reply With Quote
Old May 9, 2012, 05:33 PM   #14
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Quote:
Code:
set theScript to "Macintosh_HD/Users/jtb/Desktop/sig.sh"
tell application "Terminal"
activate
do script theScript
end tell
Any reason why it say Macintosh_HD/Users/jtb/Desktop/sig.sh: No such file or directory ? That file is definitely on the desktop.
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 05:40 PM   #15
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Code:
set theScript to "/Users/jtb/Desktop/sig.sh"
kryten2 is offline   0 Reply With Quote
Old May 9, 2012, 05:45 PM   #16
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Thanks! Is there anyway to have my script wait while the user finished the bash script before moving on to the next part?
Quote:
set theScript to "/Users/jtb/Desktop/sig.sh"
tell application "Terminal"
activate
do script theScript
end tell
wait for user to finish script here. then move on to the next part.

Quote:
contentHTML to ((path to desktop as text) & "sig.html") as alias
set contentHTML to (read contentHTML)
tell application "Microsoft Outlook"
make new signature with properties {name:name, content:contentHTML}
end tell
jtbbrandt is offline   0 Reply With Quote
Old May 9, 2012, 06:29 PM   #17
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by jtbbrandt View Post
Any reason why it say Macintosh_HD/Users/jtb/Desktop/sig.sh: No such file or directory ? That file is definitely on the desktop.
You need to use the right delimiters (slash or colon), and the right naming convention. The pathname you show is a mismatched combination of Posix file convention (slash delimiters) and classical Mac OS file convention (start with disk name).

Look at the Posix file AppleScript path, and Posix path property of an AppleScript alias object. I also recommend reading a decent AppleScript tutorial or reference doc on the difference between these two very different file naming conventions.
chown33 is offline   0 Reply With Quote
Old May 9, 2012, 06:42 PM   #18
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Code:
make new signature with properties {name:name, content:contentHTML}
I advised you not to use a name value for the name property of the properties record.

Quote from the Applescript Terminology and Apple Event Codes :

Quote:
pnam' name Property of class: action System Events : Processes Suite 2004
'pnam' name Property of class: annotation System Events : QuickTime File Suite 2005
'pnam' name Property of class: application AppleScript Language 2006
'pnam' name Property of class: application AppleScript Studio : Application Suite 2007
'pnam' name Property of class: application Cocoa Scripting : Standard Suite 2008
'pnam' name Property of class: application Finder : Finder Basics 2009
'pnam' name Property of class: attribute System Events : Processes Suite 2010
'pnam' name Property of class: column Finder : Type Definitions 2011
'pnam' name Property of class: data cell AppleScript Studio : Data View Suite 2012
'pnam' name Property of class: data column AppleScript Studio : Data View Suite 2013
'pnam' name Property of class: default entry AppleScript Studio : Application Suite 2014
'pnam' name Property of class: disk item System Events : Disk-Folder-File Suite 2015
'pnam' name Property of class: document AppleScript Studio : Document Suite 2016
'pnam' name Property of class: document Cocoa Scripting : Standard Suite 2017
'pnam' name Property of class: domain System Events : Disk-Folder-File Suite 2018
'pnam' name Property of class: file information Standard Additions : File Commands 2019
'pnam' name Property of class: folder action System Events : Folder Actions Suite 2020
'pnam' name Property of class: FTP item Standard Additions : Internet Suite 2021
'pnam' name Property of class: item AppleScript Studio : Application Suite 2022
'pnam' name Property of class: item Finder : Finder items 2023
'pnam' name Property of class: item System Events : Disk-Folder-File Suite 2024
'pnam' name Property of class: label Finder : Type Definitions 2025
'pnam' name Property of class: login item System Events : Login Items Suite 2026
'pnam' name Property of class: pasteboard AppleScript Studio : Application Suite 2027
'pnam' name Property of class: process Finder : Legacy suite 2028
'pnam' name Property of class: process System Events : Processes Suite 2029
'pnam' name Property of class: property list item System Events : Property List Suite 2030
'pnam' name Property of class: script AppleScript Language 2031
'pnam' name Property of class: script System Events : Folder Actions Suite 2032
'pnam' name Property of class: text flow AppleScript Language 2033
'pnam' name Property of class: track System Events : QuickTime File Suite 2034
'pnam' name Property of class: UI element System Events : Processes Suite 2035
'pnam' name Property of class: URL Standard Additions : Internet Suite 2036
'pnam' name Property of class: user System Events : Accounts Suite 2037
'pnam' name Property of class: web page Standard Additions : Internet Suite 2038
'pnam' name Property of class: window Cocoa Scripting : Standard Suite 2039
'pnam' name Property of class: window Finder : Window classes 2040
'pnam' name Property of class: XML attribute System Events : XML Suite 2041
'pnam' name Property of class: XML data System Events : XML Suite 2042
'pnam' name Property of class: XML element System Events : XML Suite 2043
Code:
set theScript to "/Users/jtb/Desktop/sig.sh"
tell application "Terminal"
	activate
	do script theScript in window 1
	repeat while busy of tab 1 of window 1 is true
	end repeat
end tell
Please note the in window 1 and of tab 1 of window 1. The script should wait for the shell script in the Terminal window to finish so the busy property of tab returns false. Once again all of this can be found in the appropriate dictionaries.

Last edited by kryten2; May 10, 2012 at 09:04 AM.
kryten2 is offline   0 Reply With Quote
Old May 10, 2012, 03:08 PM   #19
jtbbrandt
Thread Starter
macrumors newbie
 
Join Date: May 2012
Thanks for all of your help. This is what I've got so far:

Quote:
set theScript to "/Users/USERNAME/Desktop/SCRIPT.SH"
tell application "Terminal"
activate
tell window 1
do script theScript
end tell
repeat while busy of tab 1 of window 1 is true
end repeat
end tell


set Sig1 to "Signature"
set contentHTML to ((path to desktop as text) & "signature.html") as alias
set contentHTML to (read contentHTML)
tell application "Microsoft Outlook"
make new signature with properties {name:Sig1, content:contentHTML}
end tell
Its really great. It waits while the user completes the bash script then it goes on to add the created signature into Outlook. I need to figure out how to set it as the default script.

I tried adding to the make new signature line:

Quote:
make new signature with properties {name:name, content:contentHTML, plaintextcontent:"", includeinrandom:false}
But it just spits out an error:

Quote:
Microsoft Outlook got an error: Can’t make {name:"Sig1", content:"<br />
<div id=\"preview_box_inner\" style=\"line-height:15px;\">
<table safdlpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr>
<td style=\"padding-right:10px;\">
<img src=\"http://www.google.com/assets/images/google-logo-sm.jpg\" alt=\"logo\"/>
</td>
<td style=\"vertical-align:bottom;\" valign=\"bottom\">
<span style=\"color:#54585b; font-weight: bold; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\" id=\"sig_name\">sfd</span><br />
<span style=\"color:#54585b; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\" id=\"sig_title\">sadf</span><br />
</td>
</tr>
</table>
<table safdlpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr>
<td style=\"width:35px; padding-top:5px;\"><strong style=\"color:#9ccbe9; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\">TEL&nbsp;</strong></td>
<td style=\"padding-top:5px;\"><span style=\"color:#54585b; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\">asdf</span><br /></td>
</tr>
<tr>
<td style=\"width:35px;\"><strong style=\"color:#9ccbe9; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\">CEL&nbsp;</strong></td>
<td><span style=\"color:#54585b; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\">safd</span><br /></td>
</tr>
<tr>
<td style=\"width:35px; padding-bottom: 5px;\"><strong style=\"color:#9ccbe9; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\">FAX&nbsp;</strong></td>
<td style=\"padding-bottom: 5px;\"><span style=\"color:#54585b; font-size:8pt; font-family: Verdana, Geneva, sans-serif;\">xxx.xxx.xxxx</span><br /></td>
</tr>
<tr>
<td colspan=\"2\">
<a href=\"http://www.google.com\" style=\"color:#9ccbe9; font-weight:bold; font-size:8pt; font-family: Verdana, Geneva, sans-serif; text-decoration:none;\">www.google.com</a>
</td>
</tr>
</table>
</div>
", string:"", include in random:false} into type properties of signature.
This is the html content of my signature. I am not sure what the error is trying to tell me.
FYI: I replaced some of the things in my script with Google to hide a couple of things.
jtbbrandt is offline   0 Reply With Quote
Old May 12, 2012, 08:33 AM   #20
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
Unfortunately I don't have Outlook 2011. Those properties you tried to add are those real properties? Where did you get them? By looking in the dictionary? If so can you please post a screenshot of the relevant section of the dictionary so I can take a look at them. You've got the possibility of posting screenshots please use it. Thanks.
kryten2 is offline   0 Reply With Quote
Old May 12, 2012, 09:46 AM   #21
chown33
macrumors 603
 
Join Date: Aug 2009
Remove both additional properties. Does it work now?

Add the properties back one at a time. Which one works? Which one doesn't?

Change the HTML content to something much smaller. Now add both new properties. What happens? (That is, try it, describe exactly what you tried, post all error messages).

You wrote this:
Code:
make new signature with properties {name:name, content:contentHTML, plaintextcontent:"", includeinrandom:false}
but the error message says this (condensed):
Code:
Can’t make {name:"Sig1", content:"<html here>", string:"", include in random:false} into type properties of signature.
The red-hilited one isn't what you showed at all. Does the scripting dictionary reference show the string property being the same as plaintextcontent? Does it say plaintextcontent and content are mutually exclusive (one or the other, but not both)?
chown33 is offline   0 Reply With Quote
Old May 12, 2012, 10:43 AM   #22
kryten2
macrumors 6502a
 
Join Date: Mar 2012
Location: Belgium
This is what I found on this link : http://www.officeformachelp.com/2011...look-2011-sp1/

Quote:
Signature Suite

The Signature Suite is brand new in Outlook 14.1.0! Scripts can now manipulate signature data using these properties:

name — name of the signature
content — HTML content of the signature
plain text content — content of the signature as plain text
include in random — whether or not the signature is included in the random list
Nothing in the Signature Suite, however, enables a signature to be assigned to an account or to insert an image.
kryten2 is offline   0 Reply With Quote
Old May 12, 2012, 10:56 AM   #23
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by kryten2 View Post
content — HTML content of the signature
plain text content — content of the signature as plain text
Reading that suggests mutual exclusivity to me. That is, if one wanted a plain text signature, one would use plain text content. Conversely, if one wanted HTML in the signature, one would use content. I can't think of a logical way that one could have both at the same time.

So my suggestion is to remove the plain text content property from the failing example, and see what happens.
chown33 is offline   0 Reply With Quote
Old May 12, 2012, 02:00 PM   #24
Ap0ks
macrumors regular
 
Join Date: Aug 2008
Location: Cambridge, UK
I've tested it in Outlook 2011 and as chown33 has pointed out the two properties are mutually exclusive. If you use the contentHTML property Outlook will automatically create a plain text version of the HTML signature.

If you use the plain text content property Outlook will add a plain text signature and if sending a HTML email will format the signature to use the default HTML font.
Ap0ks is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mail 6.0 HTML signature solved jeremymarlowe OS X 10.8 Mountain Lion 9 Jul 5, 2014 03:55 AM
Applescript for Outlook 2011 for Mac teowpm Mac Programming 1 Apr 24, 2014 10:34 AM
iOS 6 HTML signature problem jhable iOS 6 0 Jan 8, 2013 01:13 PM
New HTML signature in iOS 6... NOT WORKING!? arkoh iOS 6 28 Oct 31, 2012 05:20 PM
Import HTML signature to Entourage? dbit Web Design and Development 0 Aug 22, 2012 10:17 AM

Forum Jump

All times are GMT -5. The time now is 12:17 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC