Welcome to MacBoardz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Newbie: working with lists

 
   Macintosh computer (Home) -> Apple Scripts RSS
Next:  desktop 'passepartout'?  
Author Message
Jack B. Pollack

External


Since: Dec 19, 2003
Posts: 39



(Msg. 1) Posted: Sun Aug 24, 2008 11:04 am
Post subject: Newbie: working with lists
Archived from groups: alt>comp>lang>applescript (more info?)

I am fairly new to AppleScript (but have been programming in other languages
for a long time).

I want to sort a list of 1000+ contact records (about 6 fields in each
record). I would probably do this with an array in another language. I think
AS uses "lists". When I google "applescript lists" (etc) it get a lot of
hits, but not really ones related to my real questions.

1. Is a list the best/correct way to do this?
2. What would the sample syntax be for populating this list (Sort fields:
"last name", name, phone1, phone2, email)?
3. What is the syntax to refer to field1 (last name) after passing the list
to the sort?
4. Memory wise, would a older Mac with 512MB RAM have a problem with a list
of this size?

Thanks for your help

 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Dave Balderstone

External


Since: Mar 21, 2006
Posts: 1688



(Msg. 2) Posted: Sun Aug 24, 2008 11:04 am
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

This message is not archived

 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Jack B. Pollack

External


Since: Dec 19, 2003
Posts: 39



(Msg. 3) Posted: Sun Aug 24, 2008 12:54 pm
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Dave Balderstone" wrote in message

> In article , Jack B.
> Pollack wrote:
>
> > I am fairly new to AppleScript (but have been programming in other
languages
> > for a long time).
> >
> > I want to sort a list of 1000+ contact records (about 6 fields in each
> > record).
>
> What application?
>
> > would probably do this with an array in another language. I think
> > AS uses "lists". When I google "applescript lists" (etc) it get a lot of
> > hits, but not really ones related to my real questions.
> >
> > 1. Is a list the best/correct way to do this?
>
> In AS, yes. There are available handlers to do it, so you don't have to
> reinvent the wheel.
>
> > 2. What would the sample syntax be for populating this list (Sort
fields:
> > "last name", name, phone1, phone2, email)?
>
> What application? Or, are you going to export them to a text file, sort
> that, then reimport?
>
> > 3. What is the syntax to refer to field1 (last name) after passing the
list
> > to the sort?
>
> Don't worry about it. Use an available handler. ie:
> <http://bbs.macscripter.net/viewtopic.php?pid=89978>
>
> > 4. Memory wise, would a older Mac with 512MB RAM have a problem with a
list
> > of this size?
>
> Running what OS/what version of Applescript?
>
> I would probably take the approach of creating a list of lists, IOW, a
> list of each of your lists of contact record fields, and then sort
> that.
>



Thanks for your reply.

>> I want to sort a list of 1000+ contact records (about 6 fields in each
record).
> What application?

The source is the Mac address book. I already have written so code to
extract the data, but the data is unsorted.

> What application? Or, are you going to export them to a text file, sort
> that, then reimport?
I would like to sort them in memory if possible.


> Running what OS/what version of Applescript?
This will probably have to run on OS 10.3 - 10.5, systems may have as low as
512MB. Is it realistic to sort a list of this size in memory?

> Don't worry about it. Use an available handler. ie:
> <http://bbs.macscripter.net/viewtopic.php?pid=89978>
I already have some sort code (or I can use link you provided), my question
is the syntax to create a "list" and then how to refer to elements of the
list.

Thanks
 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Michelle Steiner

External


Since: Jul 15, 2003
Posts: 3627



(Msg. 4) Posted: Sun Aug 24, 2008 12:54 pm
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Dave Balderstone

External


Since: Mar 21, 2006
Posts: 1688



(Msg. 5) Posted: Sun Aug 24, 2008 12:54 pm
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Jack B. Pollack

External


Since: Dec 19, 2003
Posts: 39



(Msg. 6) Posted: Sun Aug 24, 2008 7:39 pm
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Michelle Steiner" wrote in message

> In article ,
> "Jack B. Pollack" wrote:
>
> > I already have some sort code (or I can use link you provided), my
> > question is the syntax to create a "list" and then how to refer to
> > elements of the list.
>
> In pure Applescript, there are lists and there are records. Records
> have labels, lists do not.
>
> This is a record:
> set theRecord to {firstName:"michelle", lastName:"steiner",
> phoneNumber:"480-555-1234"}
>
> This is a list:
> set theList to {"michelle", "steiner", "480-555-1234"}
>
> Records, by their very nature, are unordered; you can't address items by
> ordinality because they don't have that nature. "Item 1 of rec" does
> not make sense. Therefore, you cannot sort records.
>
> You can make a list of records, such as
> set listOfRecords to {{firstName:"michelle", lastName:"steiner",
> phoneNumber:"480-555-1234"},{firstName:"john", lastName:"smith",
> phoneNumber:"480-555-1235"}}
>
> But I wouldn't know how to sort that.
>

Thanks for clarifying. Gona play around.
 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Jack B. Pollack

External


Since: Dec 19, 2003
Posts: 39



(Msg. 7) Posted: Sun Aug 24, 2008 7:40 pm
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Dave Balderstone" wrote in message

> In article , Jack B.
> Pollack wrote:
>
> > Thanks for your reply.
> >
> > >> I want to sort a list of 1000+ contact records (about 6 fields in
each
> > record).
> > > What application?
> >
> > The source is the Mac address book. I already have written so code to
> > extract the data, but the data is unsorted.
>
> The sample code below will let you sort on any field in each record,
> once the data is in a a"list of lists" format.
>
> >
> > > What application? Or, are you going to export them to a text file,
sort
> > > that, then reimport?
> > I would like to sort them in memory if possible.
>
> Yes.
>
> > > Running what OS/what version of Applescript?
> > This will probably have to run on OS 10.3 - 10.5, systems may have as
low as
> > 512MB. Is it realistic to sort a list of this size in memory?
>
> I'd think so. The only effect of low memory should be increasing the
> run time.
>
> >
> > > Don't worry about it. Use an available handler. ie:
> > > <http://bbs.macscripter.net/viewtopic.php?pid=89978>
> > I already have some sort code (or I can use link you provided), my
question
> > is the syntax to create a "list" and then how to refer to elements of
the
> > list.
>
> Creating a list can be done in a number of ways. Normally I would
> iterate through the data, adding each item to the end of the list
> (watch the text wrap):
>
>
> -- begin script
>
> set old_delims to AppleScript's text item delimiters
> set theUnsorted to {}
> set theData to "balderstone,dave,306-555-1212
> pollack,jack,234-555-1212
> adams,douglas,345-555-1212"
> set AppleScript's text item delimiters to return
> repeat with x from 1 to count of text items of theData
> set end of theUnsorted to text item x of theData
> end repeat
>
> (*
> {
> "balderstone,dave,306-555-1212",
> "pollack,jack,234-555-1212",
> "adams,douglas,345-555-1212"
> }
> *)
>
> set AppleScript's text item delimiters to old_delims
>
> my bubblesort(theUnsorted, 1)
> set TheSorted to the result
> return TheSorted
>
> (*
> {
> "adams,douglas,345-555-1212",
> "balderstone,dave,306-555-1212",
> "pollack,jack,234-555-1212"
> }
> *)
>
> on bubblesort(theList, sortIndex)
> -- bubble sort a list of sublists by a certain index place in each
> sublist
> set theSize to length of theList
> repeat with i from 1 to theSize
> repeat with j from 2 to (theSize - i + 1)
> if ((item sortIndex of item (j - 1) of theList) > (item
> sortIndex of item j of theList)) then
> set temp to (item (j - 1) of theList)
> set (item (j - 1) of theList) to (item j of theList)
> set (item j of theList) to temp
> end if
> end repeat
> end repeat
> return theList
> end bubblesort
>
> -- end script
>
> --
Thanks. I will play around with this tomorrow. I cant see straight anymore
tonight Smile
 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Jack B. Pollack

External


Since: Dec 19, 2003
Posts: 39



(Msg. 8) Posted: Mon Aug 25, 2008 10:25 am
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Dave Balderstone" wrote in message

> In article , Jack B.
> Pollack wrote:
>
> > Thanks for your reply.
> >
> > >> I want to sort a list of 1000+ contact records (about 6 fields in
each
> > record).
> > > What application?
> >
> > The source is the Mac address book. I already have written so code to
> > extract the data, but the data is unsorted.
>
> The sample code below will let you sort on any field in each record,
> once the data is in a a"list of lists" format.
>
> >
> > > What application? Or, are you going to export them to a text file,
sort
> > > that, then reimport?
> > I would like to sort them in memory if possible.
>
> Yes.
>
> > > Running what OS/what version of Applescript?
> > This will probably have to run on OS 10.3 - 10.5, systems may have as
low as
> > 512MB. Is it realistic to sort a list of this size in memory?
>
> I'd think so. The only effect of low memory should be increasing the
> run time.
>
> >
> > > Don't worry about it. Use an available handler. ie:
> > > <http://bbs.macscripter.net/viewtopic.php?pid=89978>
> > I already have some sort code (or I can use link you provided), my
question
> > is the syntax to create a "list" and then how to refer to elements of
the
> > list.
>
> Creating a list can be done in a number of ways. Normally I would
> iterate through the data, adding each item to the end of the list
> (watch the text wrap):
>
>
> -- begin script
>
> set old_delims to AppleScript's text item delimiters
> set theUnsorted to {}
> set theData to "balderstone,dave,306-555-1212
> pollack,jack,234-555-1212
> adams,douglas,345-555-1212"
> set AppleScript's text item delimiters to return
> repeat with x from 1 to count of text items of theData
> set end of theUnsorted to text item x of theData
> end repeat
>
> (*
> {
> "balderstone,dave,306-555-1212",
> "pollack,jack,234-555-1212",
> "adams,douglas,345-555-1212"
> }
> *)
>
> set AppleScript's text item delimiters to old_delims
>
> my bubblesort(theUnsorted, 1)
> set TheSorted to the result
> return TheSorted
>
> (*
> {
> "adams,douglas,345-555-1212",
> "balderstone,dave,306-555-1212",
> "pollack,jack,234-555-1212"
> }
> *)
>
> on bubblesort(theList, sortIndex)
> -- bubble sort a list of sublists by a certain index place in each
> sublist
> set theSize to length of theList
> repeat with i from 1 to theSize
> repeat with j from 2 to (theSize - i + 1)
> if ((item sortIndex of item (j - 1) of theList) > (item
> sortIndex of item j of theList)) then
> set temp to (item (j - 1) of theList)
> set (item (j - 1) of theList) to (item j of theList)
> set (item j of theList) to temp
> end if
> end repeat
> end repeat
> return theList
> end bubblesort
>
> -- end script
>
Dave,
The script compiles OK, but theSorted list appears to be the same as
theUnsorted after calling the function
 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Dave Balderstone

External


Since: Mar 21, 2006
Posts: 1688



(Msg. 9) Posted: Mon Aug 25, 2008 10:25 am
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Imported from groups: per prev. post (more info?)

Back to top
Login to vote
Jack B. Pollack

External


Since: Dec 19, 2003
Posts: 39



(Msg. 10) Posted: Mon Aug 25, 2008 10:45 am
Post subject: Re: Newbie: working with lists [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Dave Balderstone" wrote in message

> In article , Jack B.
> Pollack wrote:
>
> > The script compiles OK, but theSorted list appears to be the same as
> > theUnsorted after calling the function
>
> Post your data and I'll have a look. If you don't want to post it
> publicly, you can email it to me.
>
> I'll dig into it after work.
>
> --
> I kill all messages, and replies to messages, from Google Groups. See
> http://improve-usenet.org for details.

Much appreciated.
 >> Stay informed about: Newbie: working with lists 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
How do you substract two lists? - Hi, I have Set list1 to {"111","222","333","444"} Set list2 to {"333"} Set list 3 to list1 minus list2 Unfortunately this does not work. The result I am hoping for is {"111","222",...

Applescript Lists of Records??? - I'm new to Applescript but not new to programming. I need to create a list of records on the fly to collect the properties of open application windows like so: set winPositions to {} as list set winName to "" tell application "Finder&qu...

Read & Write Lists ? - Hello /Particular problem/: How to _write_ and later _read_ lists ! See I'am trying to save a *list* of positions, bounds & paths of finder windows in a text file in order to restore the finder windows at some later point. Apart from the..

How do you read dictionary property lists? - An application's dictionary says: Properties: ID integer [r/o] -- the event's unique ID subject Unicode text -- subject of the event location Unicode text -- location of the event content Unicode text -- description of the event...

Applescript Studio sample code & apple support lists - Hello again, everyone. Has anyone else here had this problem? I'm trying to learn applescript studio. It looks like a really nice environment, and a great way to start learning cocoa...BUT! A lot of the sample projects, including the stuff bundeled b...
   Macintosh computer (Home) -> Apple Scripts All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]