using cocoa interface builder with applescript

Hi. I am just wondering is this possible?

I have a script that extracts names & emails from addressbook and creates a tab delimited file.

the script takes a while to run because I have so many contacts in my addressbook, and I am wondering-- is there a simple way to create a blue status bar that fills as it does the job? Is this something that can be done? If so, can anyone please point me to some websites that have good tutorials on the subject? (mind you, I do not know C)


Some tips here:

If you are interested in the Studio way, just search this forum for “progress AND indicator”. You will find hundreds of examples :wink:

You probably just need to optimise your code a bit to eliminate the lengthy delay, e.g. by fetching all the name and email strings from Address Book at once rather than one at a time. For example, the following script outputs names and emails for a thousand people in a couple of seconds:


from appscript import *
from osax import choosenewfile
from codecs import BOM_UTF8

f = open(choosenewfile().path, 'wb')
people = app('Address Book').people
for name, emails in zip(, people.emails.value.get()):
	for email in emails:
		f.write(('%s\t%s\n' % (name, email)).encode('utf8'))

It’s in Python and requires appscript, but an AS version should perform reasonably well as long as you use the script object kludge to efficiently iterate over long lists.


This is the version Has is talking about (read/write is left to you):

tell application "Address Book" to {name, value of email} of every person


to proc(nfo)
	script o
		property x : nfo
		property y : {}
	end script
	repeat with i from 1 to count o's x's item 1
		set o's y's end to o's x's item 1's item i & tab & o's x's item 2's item i & return
	end repeat
	o's y as text
end proc

Anyway, if your script is for public consumption, I would use anyway the progress bar, which will slow down so much the process but will make happy the users :wink: → perhaps updating it every 50 or 100 iterations, so it isn’t terribly slow updating the bar every time…

Ok… Hi Everyone… I ended up getting a couple books on AppleScript Studio & Xcode so that I could figure this out… but now I am reallllllllllllllllly stuck…

Ok… so I created a window with a progress bar, and was able to get it to activate with:

on awake from nib theObject tell window "addressbook2pine" activate set maximum value of progress indicator "statusbar" to 300 tell progress indicator "statusbar" to start repeat 30 times tell progress indicator "statusbar" to increment by 10 end repeat end tell end awake from nib
And it works beautifully… Now the problem of getting this to work with my script… Here is my script which works perfectly…

[code]set emaildata to {}
set groupdata to {}
set compilationList to “”
set totalcount to 0
set totalskip to 0
activate application “Address Book”
tell application “Address Book”
set thebook to every person as list
repeat with theNames in thebook
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) 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 companydata ≠“missing value” then
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 totalcount to totalcount + 1
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 & ")"
			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 & "

set totalskip to totalskip + 1
end if
end repeat
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 tell[/code]
So now my question is… HOW do I effectively accomplish the task of this within the scope of the script & the status bar:

  1. set xyz to count thebook (all the contacts in addressbook)

  2. set progress indicator “statusbar” to maximum value XYZ

  3. each time the “repeat with thenames in the thebook” loop is fulfilled, tell progress indicator “statusbar” to increment by 1 is executed.

  4. upon completion of the script-- before the file is written, there will be a final tell progress indicator “statusbar” to increment by totalskip (so the bar completes 100%)

… I assume I can accomplish this with subroutines, but I was getting confused because I dont think I can have a tell window “addressbook2pine” while inside a tell “address book”… Which makes it very confusing how I can do all of this…

So… if anyone can help me… I will be verrrrrrrrrrry happy…