Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
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?
 

Red Menace

macrumors 6502a
May 29, 2011
578
226
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).
 

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
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
 

chown33

Moderator
Staff member
Aug 9, 2009
10,755
8,445
A sea of green
The pathname is wrong.

When using colon-separated directories, the first element must be the disk name:
Code:
 "[U]Macintosh HD[/U]: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.
 

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
The pathname is wrong.

When using colon-separated directories, the first element must be the disk name:
Code:
 "[U]Macintosh HD[/U]: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 = :Desktop
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Code:
set the_file to (path to desktop as text) & "file.html" as alias
set contentHTML to (read the_file as «class utf8»)
 

Attachments

  • Picture 2.png
    Picture 2.png
    51 KB · Views: 388

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,755
8,445
A sea of green
I put the space between the : and the D otherwise it looks like this = :Desktop

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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
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
 

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
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?
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
From the System Events dictionary :
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}
 

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
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:

#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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
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 :

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:

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
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

macrumors newbie
Original poster
May 8, 2012
9
0
Thanks! Is there anyway to have my script wait while the user finished the bash script before moving on to the next part?
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.

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
 

chown33

Moderator
Staff member
Aug 9, 2009
10,755
8,445
A sea of green
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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Code:
make new signature with properties {name:[COLOR="Red"][U]name[/U][/COLOR], 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 :

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:

jtbbrandt

macrumors newbie
Original poster
May 8, 2012
9
0
Thanks for all of your help. This is what I've got so far:

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:

make new signature with properties {name:name, content:contentHTML, plaintextcontent:"", includeinrandom:false}

But it just spits out an error:

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 </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 </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 </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.
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,755
8,445
A sea of green
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, [B]plaintextcontent:""[/B], [B]includeinrandom:false[/B]}
but the error message says this (condensed):
Code:
Can’t make {name:"Sig1", content:"<html here>", [COLOR="Red"]string:""[/COLOR], 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)?
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
This is what I found on this link : http://www.officeformachelp.com/2011/04/microsoft-updates-applescript-dictionary-for-outlook-2011-sp1/

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.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,755
8,445
A sea of green
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.
 

Ap0ks

macrumors 6502
Aug 12, 2008
316
93
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.