Create task from Contact

J

Jeremy Fieldsend

Is there an applescript I can use from the applescript menu to create a
note from a contact: "Call <contact>, <work phone no.>" and link it to
the conatct??

Thanks
 
J

Jeremy Fieldsend

Here you go. It's designed for Entourage 2004, and will replicate the
category and project, if any, of the contact to the note. If you're in
Entourage X or 2001, just remove references to theProjects and project list
below.

It lets you select more than one contact at a time of you wish, and will
make notes for all of them. If there's no work phone number, it will use the
home phone number. You could change that to 'mobile phone number' or just
remove that line. If you want to open the note after it's made, remove the
"--" before the last line 'open theNote'.

Finally - you do realize you could make a task, optionally with a reminder,
instead of a note. But you'd have to know in advance how many days in
advance to make the reminder and/or due date.


tell application "Microsoft Entourage"
try
set theSelection to selection
if class of theSelection is not list then error number -128
on error
beep
display dialog "You can only run this script on selected
contact(s)." buttons {"Cancel"} default button 1 with icon 0
return
end try

repeat with i from 1 to (count theSelection)
repeat 1 times
set theContact to item i of theSelection
if class of theContact is not contact then exit repeat -- 1
times
set theName to name of theContact
set thePhone to business phone number of theContact
if thePhone = "" then set thePhone to home phone number of
theContact
set theText to "Call " & theName & ", " & thePhone
set {theCategories, theProjects} to theContact's {category,
project list}
set theNote to make new note with properties {name:theName,
content:theText, category:theCategories, project list:theProjects}
link theNote to theContact
open theNote
end repeat
end repeat
end tell

Many thanks Paul.
 
J

Jeremy Fieldsend

Paul Berkowitz said:
Finally - you do realize you could make a task, optionally with a reminder,
instead of a note. But you'd have to know in advance how many days in
advance to make the reminder and/or due date.

Which is, of course, a much more sensible route altogether. I've tried -
unsuccessfully - to adapt your applescript. I don;t need the optional
reminder, just a task which reads "call <name>, <phone>.

Many thanks
 
P

Paul Berkowitz

Which is, of course, a much more sensible route altogether. I've tried -
unsuccessfully - to adapt your applescript. I don;t need the optional
reminder, just a task which reads "call <name>, <phone>.

Really? All you needed to do as change the word 'note' to 'task'. (I'm also
changing the variable to 'theTask' in all places just so it reads better,
but it would have worked anyway as 'theNote') I actually forgot to comment
out the 'open' part last time, so I'm doing it here. If you want it to open,
remove the "--" characters. This version makes a task with no due date and
no reminder.

P.S. I send scripts in HTML for a good reason: otherwise long lines break in
the email and would create errors when compiling. You'd have to know soe
AppleScript to know where to restore long lines by removing carriage
returns. On the other hand, I've discovered that people reading these
messages in the Google (or other) web browser have problems with scripts
containing non-ASCII (non-basic) characters like ‚ (is not equal), which
come out as commas, for example, at least in HTML, since the browser is
using Windows character format, and also break the script. So I'm trying to
rememver to always use the more verbose English alternatives like 'is not
equal to'. I may need to be reminded occasionally. Anyway, you're all better
off using Entourage or another newsreader, not Google: your messages and the
replies will appear within a min ute or so of being sent, not 12 hours or
so.


tell application "Microsoft Entourage"
try
set theSelection to selection
if class of theSelection is not list then error number -128
on error
beep
display dialog "You can only run this script on selected
contact(s)." buttons {"Cancel"} default button 1 with icon 0
return
end try

repeat with i from 1 to (count theSelection)
repeat 1 times
set theContact to item i of theSelection
if class of theContact is not contact then exit repeat -- 1
times
set theName to name of theContact
set thePhone to business phone number of theContact
if thePhone = "" then set thePhone to home phone number of
theContact
set theText to "Call " & theName & ", " & thePhone
set {theCategories, theProjects} to theContact's {category,
project list}
set theTask to make new task with properties {name:theName,
content:theText, category:theCategories, project list:theProjects}
link theTask to theContact
--open theTask
end repeat
end repeat
end tell


--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

Jeremy Fieldsend

Paul Berkowitz said:
Really? All you needed to do as change the word 'note' to 'task'. (I'm also
changing the variable to 'theTask' in all places just so it reads better,
but it would have worked anyway as 'theNote') I actually forgot to comment
out the 'open' part last time, so I'm doing it here. If you want it to open,
remove the "--" characters. This version makes a task with no due date and
no reminder.

(last request, honest)

How do I get the title of the task to read Call <name of contact>,
<phone number of contact>?

I've had several goes at amending your script without - needless to say
- much success although I have managed to get the word 'Call" in there.
(Hoo-ra)

Many thanks
 
P

Paul Berkowitz

(last request, honest)

How do I get the title of the task to read Call <name of contact>,
<phone number of contact>?

Since we've already set the variable theText to be:

set theText to "Call " & theName & ", " & thePhone

you can just set the name of the task to that same variable when making the
task:

set theTask to make new task with properties {name:theText,
content:theText, category:theCategories, project list:theProjects}

(Since you insist on replying in plain text even though I told you my
reasons for sending in HTML, you can deal with the interpolated hard
carriage return yourself when the inevitable error occurs if you paste the
whole line. Or don't paste the line but instead just change the name value
and that's all.)

This will contain the comma you wanted originally in the content. If you
don't want the comma in the task title, I leave it as an exercise to figure
out how to remove it...
I've had several goes at amending your script without - needless to say
- much success although I have managed to get the word 'Call" in there.
(Hoo-ra)

That's a start...

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
J

Jeremy Fieldsend

Paul Berkowitz said:
Since we've already set the variable theText to be:

set theText to "Call " & theName & ", " & thePhone

you can just set the name of the task to that same variable when making the
task:

set theTask to make new task with properties {name:theText,
content:theText, category:theCategories, project list:theProjects}

Many thanks.
(Since you insist on replying in plain text even though I told you my
reasons for sending in HTML, you can deal with the interpolated hard
carriage return yourself when the inevitable error occurs if you paste the
whole line. Or don't paste the line but instead just change the name value
and that's all.)

As far as I know, my newsreader (MacSoup) doesn't do html and - in any
event - one of the things I *can* do is take out the hard carriage
returns.
This will contain the comma you wanted originally in the content. If you
don't want the comma in the task title, I leave it as an exercise to figure
out how to remove it...

That's a start...

Indeed.
Thanks
 
Top