In my line of work, I regularly have to send evaluation units out to prospective customers. They email me their address and I then generate a label in Microsoft Word to print off and attach to the envelope/box I'm sending.As I do this reasonably often, and as I use an Apple Mac, I thought this would be a great excuse for creating an AppleScript program to automate the process for me.
I couldn't find examples of this in the wild, so I include the code as a starting point for anyone attempting something similar.
I've added it as an Entourage script (see image above), but it should also work in other applications just as well.
(*
Create Word label from selection v1.0
Created: 2010.09.02
Modified: 2010.09.02
*)
on run
(* Grab the selected text *)
set theText to ""
tell current application
try
set theText to the selection
if theText is "" then
error
end if
on error
display dialog ¬
"This script works on text selected in a message." buttons {"OK"}
set theText to ""
end try
end tell
(* Launch Word, confirm label positioning and generate label *)
try
if theText is not "" then
tell application "Microsoft Word"
activate
(* Collect label Row & Column data from user and ignore non-numerical entries *)
display dialog "Enter label row:" with title "Label Row" default answer "1" buttons {"Set..."} default button 1 giving up after 5
try
set labelRow to (text returned of result) as number
on error
set labelRow to 1
end try
display dialog "Enter label column:" with title "Label Column" default answer "1" buttons {"Set..."} default button 1 giving up after 5
try
set labelColumn to (text returned of result) as number
on error
set labelColumn to 1
end try
(* The magic command and pixie dust... *)
create new mailing label document mailing label object address theText single label yes row labelRow column labelColumn
end tell
end if
on error
display dialog "There was an error creating the label." buttons {"OK"}
end try
end run