Shortening variable list passed onto subroutines
Shortening variable list passed onto subroutines
- Subject: Shortening variable list passed onto subroutines
- From: Jay Louvion <email@hidden>
- Date: Tue, 17 Jan 2006 10:16:11 +0100
Title: Shortening variable list passed onto subroutines
Hi all,
I’ve been dabbling seriously for the first time (and think I’ve got it at last) in subroutines, but I was wondering if there is away of shortening a variable list passed onto it. The list is taken from a tab delimited text. Containing 17 different elements. Is there some kind of whiz way of doing this ? Maybe a subrtouine in the subroutine ? The only problem is that I need to then map the different items to different variable... Yet another subroutine ?
Thanks for the advice,
J.
This is my “gojira”:
--BEGIN SCRIPT
property htmltbl : {{"à", "à"}, {"è", "è"}, {"é", "é"}, {"ê", "ê"}, {"î", "î"}, {"ô", "ô"}, {"â", "â"}, {"û", "û"}, {"ü", "ü"}, {"ä", "ä"}, {"ö", "ö"}, {"ç", "ç"}}
using terms from application "Mail"
on perform mail action with messages incomingMessages
tell application "Mail"
repeat with msg in incomingMessages
set contentString to (content of msg) as string
set theSubject to subject of msg
try
my DefineFields_n_iCalOpts(contentString)
on error mistake
my iCalErrorLog(mistake, contentString)
end try
try
my MakeEmail(contentString)
on error mistake
my mailErrorLog(mistake, contentString)
end try
end repeat
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 1 of eventData as string
try
set EventEndDate to (items 5 thru end) of item 2 of eventData as string
on error
set EventEndDate to (items 5 thru end) of item 1 of eventData as string
end try
set StartTime to item 3 of eventData
set EndTime to item 4 of eventData
set FullStartDate to date (EventDate & " " & StartTime)
set FULLEndDate to date (EventEndDate & " " & EndTime)
set ToDoNr to item 5 of eventData
set ToDoStatus to item 6 of eventData
set ToDoAction to item 7 of eventData
set ToDoActionDetail to item 8 of eventData
set Project to item 11 of eventData
set Category to item 12 of eventData
set ThePriority to item 13 of eventData
set Photographer to item 14 of eventData
set MultiplePhotographers to textToList(Photographer, "
")
set firstwayround to 1
repeat with oneGuy in MultiplePhotographers
set OnePhotographer to (item firstwayround of MultiplePhotographers)
(*
--DISPLAY RESULTS IN DEBUGGING PROCESS -- (comment out when done)
display dialog "Date: " & EventDate & return & "Date/Heure début: " & FullStartDate & return & "Date/Heure de fin :" & FULLEndDate & return & "Photographe: " & Photographer & return & "Numéro de ToDo: " & ToDoNr & return & "Statut: " & ToDoStatus & return & "Nom de la ToDo: " & ToDoAction & return & "Description supplémentaires: " & ToDoActionDetail & return & "Projet: " & Project & return & "Catégorie: " & Category & return & "Priorité: " & ThePriority
--return
--DISPLAY RESULTS IN DEBUGGING PROCESS
*)
set text item delimiters to ""
tell application "iCal"
set rightcalendar to OnePhotographer
if OnePhotographer is "Roger" then set rightcalendar to "RogerFM"
if OnePhotographer is "Jay" then set rightcalendar to "JayFM"
set targetCal to (first calendar whose title contains rightcalendar)
if exists (first event of targetCal whose summary contains ToDoNr) then
set deleteEvents to (every event of targetCal whose summary contains ToDoNr)
repeat with thisEvent in deleteEvents
delete contents of thisEvent
end repeat
my MakeiCalEvent(targetCal, EventDate, StartTime, EndTime, FullStartDate, FULLEndDate, ToDoNr, ToDoStatus, ToDoAction, ToDoActionDetail, Project, Category, ThePriority, Photographer)
else
my MakeiCalEvent(targetCal, EventDate, StartTime, EndTime, FullStartDate, FULLEndDate, ToDoNr, ToDoStatus, ToDoAction, ToDoActionDetail, Project, Category, ThePriority, 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 "ANNULE")
repeat with thisEvent in deleteEvents
delete contents of thisEvent
end repeat
end if
end try
activate
end tell
tell application "System Events"
tell process "iCal"
keystroke "r" using {command down, shift down}
end tell
end tell
set firstwayround to (firstwayround + 1)
end repeat
end DefineFields_n_iCalOpts
on MakeiCalEvent(targetCal, EventDate, StartTime, EndTime, FullStartDate, FULLEndDate, ToDoNr, ToDoStatus, ToDoAction, ToDoActionDetail, Project, Category, ThePriority, Photographer)
tell application "iCal"
make new event at the end of events of targetCal with properties ¬
{summary:Photographer & space & ToDoNr & space & ToDoStatus & space & ToDoAction, description:"(priorité:" & ThePriority & ") " & Category & space & Project & space & ToDoActionDetail, start date:FullStartDate, end date:FULLEndDate}
end tell
end MakeiCalEvent
on MakeEmail(contentString)
set my text item delimiters to ""
set eventData to my textToList(contentString, tab)
set EventDate to (items 5 thru end) of item 1 of eventData as string
try
set EventEndDate to (items 5 thru end) of item 2 of eventData as string
on error
set EventEndDate to (items 5 thru end) of item 1 of eventData as string
end try
set StartTime to item 3 of eventData
set EndTime to item 4 of eventData
set FullStartDate to date (EventDate & " " & StartTime)
set FULLEndDate to date (EventEndDate & " " & EndTime)
set ToDoNr to item 5 of eventData
set ToDoStatus to item 6 of eventData
set ToDoAction to item 7 of eventData
set ToDoActionDetail to item 8 of eventData
set Project to item 11 of eventData
set Category to item 12 of eventData
set ThePriority to item 13 of eventData
set Photographer to item 14 of eventData
set MultiplePhotographers to textToList(Photographer, "
")
set firstwayround to 1
repeat with oneGuy in MultiplePhotographers
set OnePhotographer to (item firstwayround of MultiplePhotographers)
set {theAddress, thelink} to GetPersonalContent(OnePhotographer)
set theSubject to "ToDo pour le " & EventDate & " (" & ToDoStatus & ") - Job Studio Casagrande"
set theSource to "<br><br>Merci de prendre note de la ToDo (référence <b>" & ToDoNr & "</b>) suivant: <br><b>- " & ToDoAction & " -</b><br><br>Statut de la ToDo - <b><u>" & ToDoStatus & "</u></b><br><br>Prévue entre - <b>" & FullStartDate & "</b> et <b>" & FULLEndDate & "</b><br><br>Projet: <b>" & Project & "</b><br>Catégorie: <b>" & Category & "</b><br>Priorité: <b>" & ThePriority & "</b><br>Infos supplémentaires:<br><br><b>" & ToDoActionDetail
set theSource to str2html(theSource)
set TheName to Photographer as string
set theSender to "Studio Casagrande <email@hidden>"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject}
tell newMessage
set visible to false
set sender to theSender
make new to recipient at end of to recipients with properties {name:TheName, address:theAddress}
make new cc recipient at end of cc recipients with properties {name:"Roger", address:"email@hidden"}
set html content to "<html><head><title>" & theSubject & "</title></head><body>" & "<i>Ceci est un message automatique.</i>" & theSource & "</b><br><br>Retrouvez votre planning personnel sur le web: " & thelink & "</body></html>"
end tell
send newMessage
end tell
set firstwayround to (firstwayround + 1)
end repeat
end MakeEmail
on str2html(a)
global htmltbl
repeat with c in htmltbl
set {s, h} to c
if a contains s then
set AppleScript's text item delimiters to s
set b to text items of a
set AppleScript's text item delimiters to h
set a to b as string
end if
end repeat
set AppleScript's text item delimiters to ""
return a
end str2html
on GetPersonalContent(rightcalendar)
if rightcalendar is "Jay" then set {theAddress, thelink} to {"email@hidden", "http://ical.mac.com/studiocasagrande/JayFM"}
if rightcalendar is "Roger" then set {theAddress, thelink} to {"email@hidden", "http://ical.mac.com/studiocasagrande/RogerFM"}
return {theAddress, thelink}
end GetPersonalContent
on iCalErrorLog(ErrMssg, contentString)
set ToDoNr to first item of (my textToList(contentString, tab))
set theSubject to "iCal Error Report: ToDo " & ToDoNr
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:"Roger", address:"email@hidden"}
make new cc recipient at end of cc recipients with properties {name:"Jay", address:"email@hidden"}
set content to return & "La ToDo N° " & ToDoNr & " 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 iCalErrorLog
on mailErrorLog(ErrMssg, contentString)
set ToDoNr to first item of (my textToList(contentString, tab))
set theSubject to "iCal Error Report: ToDo " & ToDoNr
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:"Roger", address:"email@hidden"}
make new cc recipient at end of cc recipients with properties {name:"Jay", address:"email@hidden"}
set content to return & "La confirmation pour la ToDo N° " & ToDoNr & " n'a pas pu être envoyée correctement depuis Mail." & return & return & "Le message retourné par le script est le suivant: " & return & return & ErrMssg
end tell
send newMessage
end tell
set ErrMssg to ""
end mailErrorLog
--END SCRIPT
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