Hello
I)
Before applying any code you should make a backup of your address book before you test it (File->Export->Address Book Archive, or run time machine to make sure you have a current stored “good” version).
Important to having said that. Just in case. This is something you should do regulary while we try out new code, and don’t overwrite the previous backup! Make new ones.
II)
I suppose that you won’t getting any fields with missing values, i guess that the webform does that.
What I am saying here is that there will be no field with missing firstName, and no price quote mail
with missing model and every field in the price quote mail will be present if it is a price quote email.
III)
As I can’t figure out how to implement regular fields in the address book I will insert the information
in the Notes field in the Address book, which I would have found quite alright, because you will see
the information at once when you look at the card. The information will be added as you said, with
an entered data as a “start of record” specifier, and an end of record specifier, so that the info can
easily be retrieved an extracted, before you eventually scale the system up to a dbms should that be
necessary.
IV)
I will not enter the two field mentioned.
V)
I’ll have your text file with newly added brochure orders and price quote orders in mind as we go along.
VI)
I read your answer to “1” in my previous post, such that if a “type A” email are sendt twice, then
the second should be put on hold. If a Type B email is sendt, but the address book entry for the person in question is of “type A” then we suck out the data of the email and puts it where it belongs.
However if the persons address is of type B already a type B email is put in the “on Hold” mailbox.
A type A email is put in the “on hold” as long as there is an address entry in your book.
VII)
Some thoughts about a script to add notes data from an email in the “Repeats” (better name than repeats) mailbox.
It should extract info from the currently selected email and stuffs i into a record in the notes field in the address book. -This script should insert a new record on top in the notes field, but below any manually added notes at the top of the notes field This lets you have several records for a person if that should ever be necessary.
VIII)
I now have all the fieldnames
IX)
Any contact info is work related.
X)
Stuff for you to do :
Create mailboxes named: “Repeats”, “Form Submission - brochure”, “Form Submission - price quote” and when the time comes you’ll make the rule for yourself that delegates all the email to the rule script.
XI)
You must also create the same two groups in the address book “Form Submission - brochure”, “Form Submission - price quote”
XII)
I have deviced this algorithm it would be nice if you looked over it in case there is something you want to change.
(I call “Form Submission - brochure” Type A, and “Form Submission - price quote” Type B)
We have been triggered by a rule action and are about to process a mail
Gather all information from this incoming mail.
classify mail as of type.
try to find entry in address book
if addressbook entry exists then
classify by type.
if mail is of type b and address is of type a then
move address from type a to type b
update any differing address info
add quote-data into notes field
move mail into type b mailbox
update textfile.
else if mail is of type b and address is of type b then
update any differing address info
move mail to folder “repeats”.
else if mail is of type a and address exists then
update any differing address info
end if
else if address don’t exist then
create address for person and update it with info from mail accordingly.
move mail to correct mailbox.
update textfile.
end if
I’ll come back to you with something as soon as possible.
Update: This is how far we have gotten today, it would be nice if you took an overview over it.
this code is gonna change in place here until it is done, and soon I’ll be needing some help
of you to test it. But there is a lot of testing - and rewriting to be done before this is finished.
As you can read of the code; the text file is only in my thoughts at this moment, so there is functionality
to be added as well.
2010.31.05 WORKING EDITION
(*
For whom it may concern: © McUsr and put in the Public Domain
Except for hubi's excellent Address Book scripts which can be downloaded from [url=http://www.macupdate.com/info.php/id/33894/hubis-address-book-scripts]http://www.macupdate.com/info.php/id/33894/hubi's-address-book-scripts[/url]
*)
property scriptlib : {}
property A_brochure : "Form Submission - brochure"
property B_price : "Form Submission - price quote"
property C_theRepeats : "Repeats"
property D_summary : "Summary"
property mailtype : missing value
property addresstype : missing value
property mailaction : missing value
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Finder" to set mycontainer to (path to the scripts folder from user domain) as text
set scriptlib to load script (mycontainer & "Hubis Address Book Scripts:_hubionmac's AddressBook-scripts-lib.scpt") as alias
set mailtype to "0"
set mailaction to "none so far"
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
my report's initiateReports((path to desktop))
repeat with eachMessage in theMessages
set mailtype to A_brochure
set theSender to sender of eachMessage
set theSubject to subject of eachMessage
set theText to content of eachMessage
set theFirstName to my own's getParameters("FirstName", theText) -- General info for both kind of mails.
set theLastName to my own's getParameters("LastName", theText)
if theFirstName is "" and theLastName is "" then
my report's incrementNumberOfRepeats()
move eachMessage to mailbox C_theRepeats
exit repeat
end if
-- I take it for granted that it is ok if any of those are missing.
set theStreet to my own's getParameters("Address", theText)
set theCity to my own's getParameters("City", theText)
set theState to my own's getParameters("State", theText)
set theZip to my own's getParameters("ZipCode", theText)
set theCountry to my own's getParameters("Country", theText)
-- info specific for the Price quote mails.
set theModel to my own's getParameters("model", theText) -- if *any* of the following fields are set we regard the mail as a price quote.
if theModel is not "" then set mailtype to B_price
set theStrings to my own's getParameters("strings", theText)
if theStrings is not "" then set mailtype to B_price
set theFrets to my own's getParameters("frets", theText)
if theFrets is not "" then set mailtype to B_price
set thePickups to my own's getParameters("pickups", theText)
if thePickups is not "" then set mailtype to B_price
set theFinish to my own's getParameters("finish", theText)
if theFinish is not "" then set mailtype to B_price
set theCustomColor to my own's getParameters("customColor", theText)
if theCustomColor is not "" and theCustomColor is not "Didn't see the color or finish you want Enter it here" then set mailtype to B_price
set theCustomExoticTop to my own's getParameters("customExoticTop", theText)
if theCustomExoticTop is not "" and theCustomExoticTop is not "Didn't see the top you want Enter it here" then set mailtype to B_price
tell application "Address Book" -- checking if there is an entry in the addressbook for this person.
set cardCount to my own's matchingByNameCardCount(theFirstName, theLastName)
if cardCount is not 0 then -- there exist such a person
set addresstype to "0"
ignoring case
repeat with aPerson in (every person of group B_price)
if my own's foundMatchingPerson(aPerson, theFirstName, theLastName, theSender) then
copy contents of aPerson to thePerson
set addresstype to B_price
exit repeat
end if
end repeat
end ignoring
if addresstype is "0" then
ignoring case
repeat with aPerson in (every person of group A_brochure)
if my own's foundMatchingPerson(aPerson, theFirstName, theLastName, theSender) then
copy contents of aPerson to thePerson
set addresstype to A_brochure
exit repeat
end if
end repeat
end ignoring
end if
if addresstype is "0" then -- the person wasn't in any group, we will assign him/her according to our mail.
if theFirstName is not "" and theLastName is not "" then -- we can just take the first matching person.
set thePerson to item 1 of my own's allPartiallyMatchingPersons(theFirstName, theLastName)
add thePerson to group mailtype
-- we are fetching the individual elements and doesn't bother to compare if they are non-existan.
my own's refreshAddress(thePerson, theStreet, theCity, theState, theZip, theCountry)
set mailaction to "move to " & mailtype
if mailtype is B_price then my own's createPriceQuotationNote(thePerson, theModel, theStrings, theFrets, thePickups, theFinish, theCustomColor, theCustomExoticTop)
else -- either firstname is "" or lastname is "" we must search among allPersons in addressbook.
set allPersons to my own's allPartiallyMatchingPersons(theFirstName, theLastName)
ignoring case
repeat with aPerson in allPersons
if my own's foundMatchingPerson(aPerson, theFirstName, theLastName, theSender) then
set addresstype to mailtype -- here we must move the person to the correct addressgroup.
add aPerson to group mailtype
my own's refreshAddress(aPerson, theStreet, theCity, theState, theZip, theCountry)
set mailaction to "move to " & mailtype
if mailtype is B_price then my own's createPriceQuotationNote(thePerson, theModel, theStrings, theFrets, thePickups, theFinish, theCustomColor, theCustomExoticTop)
exit repeat
end if
end repeat
end ignoring
if addresstype is "0" then -- didnt find any match among all partially matching persons - must then create new card.
set thePerson to my own's makeNewAddressCard(theFirstName, theLastName, theSender, theStreet, theCity, theState, theZip, theCountry, mailtype)
set addresstype to mailtype
set mailaction to "move to " & mailtype
if mailtype is B_price then my own's createPriceQuotationNote(thePerson, theModel, theStrings, theFrets, thePickups, theFinish, theCustomColor, theCustomExoticTop)
end if
end if
else -- there was an existing card in group - Applies rules for "repeats" and promoting of addressgroup.
if addresstype is A_brochure and mailtype is B_price then -- As allways update any fields in address card that needs updating
my own's refreshAddress(thePerson, theStreet, theCity, theState, theZip, theCountry)
my own's createPriceQuotationNote(thePerson, theModel, theStrings, theFrets, thePickups, theFinish, theCustomColor, theCustomExoticTop)
remove thePerson from group A_brochure
add thePerson to group B_price
set mailaction to "move to " & B_price
else -- addresstype is b_price and mailtype is B_price or mailtype is A_brochure: mail goes to "Repeats"
my own's refreshAddress(thePerson, theStreet, theCity, theState, theZip, theCountry)
set mailaction to "move to " & C_theRepeats
end if
end if
else -- we have a new person here.
set thePerson to my own's makeNewAddressCard(theFirstName, theLastName, theSender, theStreet, theCity, theState, theZip, theCountry, mailtype)
set addresstype to mailtype
set mailaction to "move to " & mailtype
if mailtype is B_price then -- We must add a note to it -the note starts with current date.
my own's createPriceQuotationNote(thePerson, theModel, theStrings, theFrets, thePickups, theFinish, theCustomColor, theCustomExoticTop)
set mailaction to "move to " & B_price
-- add to text file.
end if
end if
save
end tell --address book
-- back in the mail scope so we will clean up a little bit.
if mailaction is "move to " & A_brochure then
move eachMessage to mailbox A_brochure
my report's flushContactInfoRecord(A_brochure, theFirstName, theLastName, theStreet, theCity, theZip, theState, theCountry, theSender) -- (Email)
my report's incrementNumberOfBrochures()
else if mailaction is "move to " & B_price then
move eachMessage to mailbox B_price
my report's flushContactInfoRecord(B_price, theFirstName, theLastName, theStreet, theCity, theZip, theState, theCountry, theSender) -- (Email)
my report's incrementNumberOfPriceQuotes()
my report's flushPriceQuotationNote(theModel, theStrings, theFrets, thePickups, theFinish, theCustomColor, theCustomExoticTop)
else if mailaction is "move to " & C_theRepeats then
move eachMessage to mailbox C_theRepeats
my report's incrementNumberOfRepeats()
else
display dialog "Bad mail action"
end if
end repeat
set AppleScript's text item delimiters to tids
-- end tell
end perform mail action with messages
end using terms from
-- -- -- --
script report
property price : 1
property brochure : 2
property repeats : 3
property summaryReportTemplate : {}
global brochuresFilename, pricesFilename, summaryFilename, curdate
on initiateReports(initalPath)
set curdate to dateString()
set brochuresFilename to (initalPath & (parent's A_brochure & curdate)) as Unicode text
verifyFile(brochuresFilename)
set pricesFilename to (initalPath & (parent's B_price & curdate)) as Unicode text
verifyFile(pricesFilename)
set summaryFilename to (initalPath & (parent's D_summary & curdate)) as Unicode text
makeSummaryReportTemplate(curdate) -- ALLWAYS HERE UNTIL FINISHED DEBUGGING SOME DAY
try -- if the summaryReport file doesn't exist, we initate it and anything else needed...
summaryFilename as alias
on error e number n
set fn to POSIX path of summaryFilename -- as Unicode text
do shell script "touch " & quoted form of fn
set tempReport to createInitialReport()
writeSummaryReport(summaryFilename, tempReport)
end try
end initiateReports
on incrementNumberOfBrochures()
updateTotalReport(brochure)
end incrementNumberOfBrochures
on incrementNumberOfPriceQuotes()
updateTotalReport(price)
end incrementNumberOfPriceQuotes
on incrementNumberOfRepeats()
updateTotalReport(repeats)
end incrementNumberOfRepeats
on updateTotalReport(repType)
local theNumbers
set theNumbers to readReport(summaryFilename)
if repType is 1 then
set priceQuoteNumbers to text item 2 of theNumbers as number
set priceQuoteNumbers to makeThreeDigitNumber((priceQuoteNumbers + 1))
set brouchuresNumbers to text item 3 of theNumbers
set repeatsNumbers to text item 4 of theNumbers
else if repType is 2 then
set priceQuoteNumbers to text item 2 of theNumbers
set brouchuresNumbers to text item 3 of theNumbers as number
set brouchuresNumbers to makeThreeDigitNumber((brouchuresNumbers + 1))
set repeatsNumbers to text item 4 of theNumbers
else -- reptype is 3
set priceQuoteNumbers to text item 2 of theNumbers
set brouchuresNumbers to text item 3 of theNumbers
set repeatsNumbers to text item 4 of theNumbers as number
set repeatsNumbers to makeThreeDigitNumber((repeatsNumbers + 1))
end if
set totalNumbers to text item 5 of theNumbers as number
set totalNumbers to makeThreeDigitNumber((totalNumbers + 1))
set text item 2 of theNumbers to priceQuoteNumbers
set text item 3 of theNumbers to brouchuresNumbers
set text item 4 of theNumbers to repeatsNumbers
set text item 5 of theNumbers to totalNumbers
set tempReport to updateReport(theNumbers)
writeSummaryReport(summaryFilename, tempReport)
end updateTotalReport
on makeThreeDigitNumber(aNumber)
set aNumber to aNumber as text
if length of aNumber < 2 then set aNumber to "0" & aNumber
if length of aNumber < 3 then set aNumber to "0" & aNumber
return aNumber
end makeThreeDigitNumber
on updateReport(aNumberStringList)
copy summaryReportTemplate to tempReport
repeat with i from 2 to 5
set text item i of tempReport to (text item i of tempReport & text item i of aNumberStringList)
end repeat
return tempReport
end updateReport
on makeSummaryReportTemplate(theDate)
local tids
if summaryReportTemplate is {} then -- kun mens debugger
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "_"}
set newDate to text items of theDate
set AppleScript's text item delimiters to "."
set theDate to newDate as text
set AppleScript's text item delimiters to tids
set theHeading to ("Incoming Mail" & space & theDate)
set end of summaryReportTemplate to theHeading
set thePriceQuotesLine to ("Number of Price Quotes" & tab & tab & ":" & tab)
set end of summaryReportTemplate to thePriceQuotesLine
set theBrochureRequestsLine to ("Number of Brochure Requests" & tab & ":" & tab)
set end of summaryReportTemplate to theBrochureRequestsLine
set theNumberOfRepeats to ("Number of Repeats" & tab & tab & ":" & tab)
set end of summaryReportTemplate to theNumberOfRepeats
set totalIncomingMailLine to ("Total Mail" & tab & tab & "\t:" & tab)
set end of summaryReportTemplate to totalIncomingMailLine
end if
end makeSummaryReportTemplate
on createInitialReport()
copy my summaryReportTemplate to tempReport
set text item 2 of tempReport to (text item 2 of tempReport & "000")
set text item 3 of tempReport to (text item 3 of tempReport & "000")
set text item 4 of tempReport to (text item 4 of tempReport & "000")
set text item 5 of tempReport to (text item 5 of tempReport & "000")
return tempReport
end createInitialReport
on readReport(aFileName) -- we just extract the numbers from the fields of the summary data record
local tids
set pu to POSIX path of aFileName
set cmdstr to "cat " & quoted form of pu
set cmdstr to cmdstr & " |sed -n s/^[^0-9][^0-9]*//p"
set ourtext to do shell script cmdstr
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set summaryNumbers to text items of ourtext as list
set AppleScript's text item delimiters to tids
return summaryNumbers
end readReport
-- takes our list of lines in the report converts it to pure text and writes out the file.
on writeSummaryReport(aFileName, theText)
local tids
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, (ASCII character 10)}
set theText to text items of theText as text
try
set fileRef to open for access aFileName with write permission
set eof fileRef to 0
try
write theText to fileRef
end try
close access fileRef
end try
set AppleScript's text item delimiters to tids
end writeSummaryReport
on flushContactInfoRecord(aRecordType, aFirstName, aLastName, aStreet, aCity, aZip, aState, aCountry, anEmail)
local contactInfo, tids
set contactInfo to {}
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, "_"}
set theDate to text items of curdate
set AppleScript's text item delimiters to "."
set theDate to theDate as text
set AppleScript's text item delimiters to tids
set theHeading to (aRecordType & " Registration date:" & space & theDate)
set end of contactInfo to theHeading
set aLineSpace to ""
set end of contactInfo to aLineSpace
set theNameLine to ("Name" & tab & tab & aFirstName & space & aLastName)
set end of contactInfo to theNameLine
set emailLine to ("Email:" & tab & tab & anEmail)
set end of contactInfo to emailLine
set addressLine1 to ("Address" & tab & tab & aStreet & ", " & aZip & " " & aCity)
set end of contactInfo to addressLine1
set addressLine2 to ("State:" & tab & tab & aState)
set end of contactInfo to addressLine2
set addressLine3 to ("Country:" & tab & aCountry)
set end of contactInfo to addressLine3
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, (ASCII character 10)}
set contactInfo to text items of contactInfo as text
set contactInfo to contactInfo & (ASCII character 10)
set AppleScript's text item delimiters to tids
if aRecordType is parent's A_brochure then
set contactInfo to contactInfo & (ASCII character 10)
appendToFile(contactInfo, brochuresFilename)
else
appendToFile(contactInfo, pricesFilename)
end if
end flushContactInfoRecord
-- adds a price quotation record to the notes of the address book
on flushPriceQuotationNote(aModel, aStrings, aFrets, aPickups, aFinish, aCustomColor, aCustomExoticTop)
local priceInfo, tids
set priceInfo to {}
set modelData to "Strings:" & tab & aModel
set end of priceInfo to modelData
set stringData to "Strings:" & tab & aStrings
set end of priceInfo to stringData
set fretsData to "Frets:" & tab & tab & aFrets
set end of priceInfo to fretsData
set pickupsData to "Pickups:" & tab & aPickups
set end of priceInfo to pickupsData
set finishData to "Finish" & tab & tab & aFinish
set end of priceInfo to finishData
if aCustomColor is not "Didn't see the color or finish you want Enter it here" then
set customColorData to "customColor:" & tab & aCustomColor
set end of priceInfo to customColorData
end if
if aCustomExoticTop is not "Didn't see the top you want Enter it here" then
set customExitcTopData to "CustomExoticTop:" & tab & aCustomExoticTop
set end of priceInfo to customExitcTopData
end if
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, (ASCII character 10)}
set priceInfo to text items of priceInfo as text
set priceInfo to priceInfo & (ASCII character 10) & (ASCII character 10)
set AppleScript's text item delimiters to tids
appendToFile(priceInfo, pricesFilename)
end flushPriceQuotationNote
-- for appending a record at a time with data.
to appendToFile(theText, theFile)
local theFile_ID, theFile_eof, tids
try
set theFile_ID to open for access theFile with write permission
on error e number n
display dialog e & " " & n & "Open file error"
return "Open file error"
end try
try
set theFile_eof to get eof theFile_ID
write theText to theFile_ID starting at (theFile_eof + 1)
on error e number n
display dialog e & " " & n & "Seek/write error"
close access theFile_ID
return "Seek/write error"
end try
try
close access theFile_ID
on error e number n
display dialog e & " " & n & "Close error"
return "Close error"
end try
return true
end appendToFile
on verifySummaryReport(reportname)
try -- if the summaryReport file doesn't exist, we initate it and anything else needed...
reportname as alias
on error e number n
set fn to POSIX path of reportname -- as Unicode text
do shell script "touch " & quoted form of fn
set tempReport to createInitialReport()
writeSummaryReport(summaryFilename, tempReport)
end try
end verifySummaryReport
on verifyFile(theFileName)
try
theFileName as alias
set found to true
on error
set fn to POSIX path of theFileName -- as Unicode text
do shell script "touch " & quoted form of fn
end try
end verifyFile
to readFile(theFile)
try
set theFile_ID to open for access (theFile as alias)
on error e number n
display dialog e & " " & n & "Open file error"
return "Open file error"
end try
try
set theFileinput to read theFile_ID as string
on error
close access theFile_ID
display dialog e & " " & n & "Read file error"
return "Read file error"
end try
try
close access theFile_ID
on error
display dialog e & " " & n & "Close file error"
return "Read file error"
end try
return theFileinput
end readFile
on dateString()
copy (current date) to this_date
set mnumber to (month of this_date as number) as text
if length of mnumber is 1 then set mnumber to "0" & mnumber
set dnumber to (day of this_date as number) as text
if length of dnumber is 1 then set dnumber to "0" & dnumber
set ynumber to year of this_date
set mdate to ynumber & "_" & mnumber & "_" & dnumber as text
-- display dialog mdate
end dateString
end script
-- -- -- --
script own
on makeNewAddressCard(herFirstName, herLastname, herMailAddress, herStreet, herCity, herState, herZip, herCountry, herMailType)
local thePerson
tell application "Address Book"
if herFirstName is "" then
set thePerson to (make new person with properties {last name:herLastname})
else if herLastname is "" then
set thePerson to (make new person with properties {first name:herFirstName})
else -- got both
set thePerson to (make new person with properties {first name:herFirstName, last name:herLastname})
end if
make new email at end of emails of thePerson with properties {label:"Work", value:herMailAddress}
make new address at end of addresses of thePerson with properties {label:"Work", street:herStreet, city:herCity, state:herState, zip:herZip, country:herCountry}
add thePerson to group herMailType
end tell
return thePerson
end makeNewAddressCard
on foundMatchingPerson(herPerson, herFirstName, herLastname, herMailAddress)
tell application "Address Book"
set found to false
if herFirstName is "" and herLastname is last name of herPerson then
set found to true
else if herLastname is "" and herFirstName is first name of herPerson then
set found to true
else if herFirstName is first name of herPerson and herLastname is last name of herPerson then
set found to true
end if
if found is false then return false
-- set foundAddress to (get email of herPerson whose value contains herMailAddress) -- construct stolen from StefanK as alt. to repeat - end repeat.
set herMailAddresses to (value of every email of herPerson)
repeat with oneOfHerEmailAddrs in herMailAddresses
if contents of oneOfHerEmailAddrs is herMailAddress then
return true
end if
end repeat
return false
end tell
end foundMatchingPerson
on matchingByNameCardCount(herFirstName, herLastname)
tell application "Address Book"
if herFirstName is "" then
set allMatchingPersons to (every person whose last name is herLastname)
else if herLastname is "" then
set allMatchingPersons to (every person whose first name is herFirstName)
else -- got both
set allMatchingPersons to (every person whose first name is herFirstName and last name is herLastname)
end if
end tell
set cardCount to count of allMatchingPersons
return cardCount
end matchingByNameCardCount
on allPartiallyMatchingPersons(herFirstName, herLastname)
tell application "Address Book"
if herFirstName is "" then
set allMatchingPersons to (every person whose last name is herLastname)
else if herLastname is "" then
set allMatchingPersons to (every person whose first name is herFirstName)
else
set allMatchingPersons to (every person whose first name is herFirstName and last name is herLastname)
end if
end tell
return allMatchingPersons
end allPartiallyMatchingPersons
-- adds a price quotation record to the notes of the address book
on createPriceQuotationNote(aPerson, aModel, aStrings, aFrets, aPickups, aFinish, aCustomColor, aCustomExoticTop)
local tids
tell application "Address Book"
set noteValue to note of aPerson
if noteValue is in {missing value, space} then set noteValue to ""
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ""}
set noteValue to noteValue & (my B_price & " " & report's curdate & return) -- Start record
set noteValue to noteValue & "Model:" & tab & tab & aModel & return
set noteValue to noteValue & "strings:" & tab & tab & aStrings & return
set noteValue to noteValue & "frets:" & tab & tab & aFrets & return
set noteValue to noteValue & "pickups:" & tab & tab & aPickups & return
set noteValue to noteValue & "finish" & tab & tab & aFinish & return
if aCustomColor is not "Didn't see the color or finish you want Enter it here" then
set noteValue to noteValue & "customColor:" & tab & aCustomColor & return
end if
if aCustomExoticTop is not "Didn't see the top you want Enter it here" then
set noteValue to noteValue & "customExoticTop:" & tab & aCustomExoticTop & return
end if
set noteValue to noteValue & ("End of " & B_price & return) -- End record
set note of aPerson to noteValue
end tell
set AppleScript's text item delimiters to tids
end createPriceQuotationNote
-- freshens addressess
on refreshAddress(aPerson, aStreet, aCity, aState, aZip, aCountry)
local theAddresses
tell application "Address Book"
set theAddresses to (every address of aPerson whose label is "work")
if (count of theAddresses) is 0 then
set theAddress to make new address at end of addresses of aPerson with properties {label:"Work", street:aStreet, city:aCity, state:aState, zip:aZip, country:aCountry}
else
-- we are fetching the individual elements and doesn't bother to compare if they are non-existan.
set theAddress to item 1 of theAddresses
if not aCity is "" then set city of theAddress to aCity
if not aStreet is "" then set street of theAddress to aStreet
if not aState is "" then set state of theAddress to aState
if not aZip is "" then set zip of theAddress to aZip
if not aCountry is "" then set country of theAddress to aCountry
end if
end tell
end refreshAddress
on getParameters(denotator, aText)
local the_res, tids
set the_res to ""
tell aText
set pars to every paragraph
repeat with aPar in pars
if contents of aPar is not "" and contents of aPar is not " " then
ignoring case
try
if first word of aPar contains denotator then
set the_res to words 2 thru -1 of aPar
exit repeat
end if
end try
end ignoring
end if
end repeat
end tell
if the_res is not "" then
if denotator is in {"FirstName", "LastName", "Address", "City"} then
if denotator is "Address" then -- split into words and capitalize each
set the_res to capitalizeString(the_res)
else
set the_res to parent's scriptlib's do_string(2, the_res as text)
end if
else if denotator contains "Country" then
ignoring case
if the_res contains "USA" or the_res contains "UK" then
set the_res to parent's scriptlib's do_string(3, the_res as text)
else
set the_res to my capitalizeString(the_res)
end if
end ignoring
else
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
set the_res to the_res as text
set AppleScript's text item delimiters to tids
end if
end if
return the_res
end getParameters
on capitalizeString(thestring)
local tids
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
set thewords to text items of thestring
set thestring to ""
repeat with aWord in thewords
set tmp_word to scriptlib's do_string(2, aWord as text)
set thestring to thestring & tmp_word & " "
end repeat
set AppleScript's text item delimiters to {""}
set thestring to characters 1 thru -2 of thestring as text
set AppleScript's text item delimiters to tids
return thestring
end capitalizeString
end script
Best Regards
McUsr