Mail 1.0 snobbing commands ?
Mail 1.0 snobbing commands ?
- Subject: Mail 1.0 snobbing commands ?
- From: Jay Louvion <email@hidden>
- Date: Thu, 29 Dec 2005 12:21:47 +0100
Title: Mail 1.0 snobbing commands ?
Hi again,
Here is my last version of the script, which works fine on Mail 2.0, but somehow sometimes ignores parts of the command (particularly the one about making an event (MakeiCalEvent subroutine), it just moves on to the relaod calendars bit). When run manually on a selected item, it _allways_ works fine. It’s just the triggered action script that fails from time to time. REAL FRUSTRATING.
I would certainly appreciate your remarks on any bit of this code, since it’s my first _real_ go at subroutines (wow are those things useful when adapting scripts !)
TIA,
J.
using terms from application "Mail"
on perform mail action with messages incomingMessages
tell application "Mail"
try
repeat with msg in incomingMessages
set contentString to (content of msg) as string
set theSubject to subject of msg
tell msg
if (get read status) is false then set read status to true
end tell
my DefineFields_n_iCalOpts(contentString)
end repeat
on error mistake
my mailErrorLog(mistake, contentString)
end try
end tell
end perform mail action with messages
on run
tell application "Mail" to set sel to selection
tell me to perform mail action with messages sel
end run
end using terms from
------SUBS-----------
------------------------
on textToList(thisText, delim)
set resultList to {}
set {tid, my text item delimiters} to {my text item delimiters, delim}
try
set resultList to every text item of thisText
set my text item delimiters to tid
on error
set my text item delimiters to tid
end try
return resultList
end textToList
on DefineFields_n_iCalOpts(contentString)
set eventData to my textToList(contentString, tab)
set EventDate to (items 5 thru end) of item 2 of eventData as string
set StartTime to item 3 of eventData
set EndTime to item 4 of eventData
set EventStartDate to date (EventDate & " " & StartTime)
set EventEndDate to date (EventDate & " " & EndTime)
set JoursAdd to item 14 of eventData
set EventRecurrence to "FREQ=DAILY;INTERVAL=1;COUNT=" & (JoursAdd + 1) as string
set JobNr to item 1 of eventData
set JobStatus to item 5 of eventData
set eventName to item 6 of eventData
set ClientFirstName to item 7 of eventData
set ClientLastName to item 8 of eventData
set ClientCellPhone to item 9 of eventData
set EventDescription to item 13 of eventData
set WebCode to item 10 of eventData
set Photographer to item 15 of eventData
(*
--DISPLAY RESULTS IN DEBUGGING PROCESS -- (comment out when done)
display dialog "Date: " & EventDate & return & "Date/Heure début: " & EventStartDate & return & "Date/Heure de fin :" & EventEndDate & return & "Jours additionels: " & EventRecurrence & return & "Photographe: " & Photographer & return & "Numéro de Job: " & JobNr & return & "Statut: " & JobStatus & return & "Nom du Job: " & eventName & return & "Prénom du client: " & ClientFirstName & return & "Nom du client: " & ClientLastName & return & "Téléphone portable: " & ClientCellPhone & return & "Description supplémentaire: " & EventDescription & return & "Code LaGalerie: " & WebCode
--DISPLAY RESULTS IN DEBUGGING PROCESS
*)
set text item delimiters to ""
tell application "iCal"
set rightcalendar to Photographer
if Photographer is "Didier" then set rightcalendar to "Did-34eqfz"
if rightcalendar is "Jay" then set rightcalendar to "Ja-93slij"
set targetCal to (first calendar whose title contains rightcalendar)
if exists (first event of targetCal whose summary contains JobNr) then
set deleteEvents to (every event of targetCal whose summary contains JobNr)
repeat with thisEvent in deleteEvents
delete contents of thisEvent
end repeat
my MakeiCalEvent(targetCal, EventDate, StartTime, EndTime, EventStartDate, EventEndDate, JoursAdd, EventRecurrence, JobNr, JobStatus, eventName, ClientFirstName, ClientLastName, ClientCellPhone, EventDescription, WebCode, Photographer)
else
my MakeiCalEvent(targetCal, EventDate, StartTime, EndTime, EventStartDate, EventEndDate, JoursAdd, EventRecurrence, JobNr, JobStatus, eventName, ClientFirstName, ClientLastName, ClientCellPhone, EventDescription, WebCode, Photographer)
end if
try
if exists (first event of targetCal whose summary contains "ANNULE") then
set deleteEvents to (every event of targetCal whose summary contains JobNr)
repeat with thisEvent in deleteEvents
delete contents of thisEvent
end repeat
end if
end try
activate
end tell
delay 1
tell application "System Events"
tell process "iCal"
keystroke "r" using {command down, shift down}
end tell
end tell
end DefineFields_n_iCalOpts
on MakeiCalEvent(targetCal, EventDate, StartTime, EndTime, EventStartDate, EventEndDate, JoursAdd, EventRecurrence, JobNr, JobStatus, eventName, ClientFirstName, ClientLastName, ClientCellPhone, EventDescription, WebCode, Photographer)
tell application "iCal"
make new event at the end of events of targetCal with properties ¬
{summary:Photographer & space & JobNr & space & eventName & space & JobStatus & space & WebCode, description:ClientFirstName & space & ClientLastName & space & ClientCellPhone & space & EventDescription, start date:EventStartDate, end date:EventEndDate, recurrence:EventRecurrence}
end tell
end MakeiCalEvent
on mailErrorLog(ErrMssg, contentString)
set JobNr to first item of (my textToList(contentString, tab))
set theSubject to "iCal Error Report: Job " & JobNr
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject}
tell newMessage
set visible to false
set sender to "email@hidden"
make new to recipient at end of to recipients with properties {name:"Didier", address:"email@hidden"}
make new cc recipient at end of cc recipients with properties {name:"Jay", address:"email@hidden"}
set content to return & "Le Job N° " & JobNr & " n'a pas pu être enregistré correctement dans iCal." & return & return & "Le message retourné par le script est le suivant: " & return & return & ErrMssg
end tell
send newMessage
end tell
end mailErrorLog
Jay Louvion
Studio Casagrande
3, rue Müller-Brun
1208 Geneva
T+4122 840 3272
F+4122 840 3271
skypeme:
jaylouvion
www.studiocasagrande.com
P Please consider the environment before printing this email.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden