Hi… I am working on a version of my script that utilizes interface builder in applescript studio-- but before I can do that, I need to make sure that my script will work using many subroutines rather than how it was previously (in one big tell statement)… Currently, I am unable to get applescript to carry over the information from “theNames” and “theBook” and be able to extract the appropriate information out of them— and I’m not sure if I am going about this the right way or not-- using global??? please help!
The script never seems to make it eto the gatherdata subroutine, as I never get a “i’m here” message…
global thebook
global theNames
global totalskip
set emaildata to {}
set groupdata to {}
set compilationList to ""
set totalskip to 0
set thebook to {}
set totalcount to 0
my getpeople(thebook, totalcount)
repeat with theNames in thebook
my gatherdata(theNames)
end repeat
my writefile(compilationList, totalskip, totalcount)
on getpeople(thebook, totalcount)
activate application "Address Book"
tell application "Address Book"
set thebook to every person as list
set totalcount to (count thebook)
end tell
end getpeople
on writefile(compilationList, totalcount)
display dialog "converted " & totalcount & " email addresses and skipped " & totalskip & " items"
set docName to choose file with prompt "Choose pine addressbook file" default location (path to home folder) with invisibles
set docPointer to (open for access docName with write permission)
set eof of docPointer to 0
write compilationList to docPointer as «class utf8»
close access docPointer
end writefile
on gatherdata(compilationList, totalcount)
tell application "Address Book"
display dialog "im here"
set theEmails to {}
set thegroups to {}
set finalemail to "("
set finalgroup to ""
set currentemail to 0
set currentgroup to 0
set commentfield to ""
set nickfield to ""
set fcc to ""
set namefield to the (name of theNames)
set emaildata to the (email of theNames)
set companydata to the (organization of theNames)
set companydatat to the (organization of theNames) as string
set groupdata to the (group of theNames)
set notedata to the (note of theNames)
set notedatat to notedata as string
if notedatat ≠"missing value" then
set AppleScript's text item delimiters to "
"
set temp to text items of notedata
set AppleScript's text item delimiters to space
set notedata to temp's text items as string
set AppleScript's text item delimiters to ""
set commentfield to notedata
end if
if companydatat ≠"missing value" then
set AppleScript's text item delimiters to " "
set temp to text items of companydata
set AppleScript's text item delimiters to "_"
set companydata to temp's text items as string
set AppleScript's text item delimiters to ""
set nickfield to companydata
end if
if emaildata ≠{} then
repeat with thisEmailRecord in emaildata
copy the value of thisEmailRecord to the end of theEmails
end repeat
set emailnumbers to count theEmails
if emailnumbers > 1 then
repeat emailnumbers times
set currentemail to currentemail + 1
set finalemail to (finalemail & item currentemail of theEmails as string)
if currentemail ≠emailnumbers then
set finalemail to finalemail & ","
end if
end repeat
set finalemail to finalemail & ")"
else
set finalemail to theEmails as string
end if
-- pine .addressbook format = nick, name, email, fcc, comment
set pineline to nickfield & tab & namefield & tab & finalemail & tab & fcc & tab & commentfield
set compilationList to compilationList & pineline & "
"
else
set totalskip to totalskip + 1
end if
end tell
end gatherdata