• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: parsing the results of last night's headache
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing the results of last night's headache


  • Subject: Re: parsing the results of last night's headache
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 3 Jan 2011 01:32:45 -0600

On Jan 02, 2011, at 22:44, Joshua Whalen wrote:
the script seems to choke on extracting the data I want from the list.
______________________________________________________________________

Hey Joshua,

I think I'd start with a little simplification:

tell application "Mail"
set theMessages to messages of inbox whose read status is false and subject contains "[Gizmo] Voicemail from:"
end tell

This gets you a list of message specifiers, and you can then go to town extracting the information you want.

set messageSubjectList to {}
set messageFromList to {}
tell application "Mail"
set theMessages to messages of inbox whose read status is false and subject contains "[Gizmo] Voicemail from:"
if theMessages ≠ {} then
repeat with ndx in theMessages
tell ndx
set end of messageSubjectList to its subject
set end of messageFromList to sender
end tell
end repeat
{messageSubjectList, messageFromList}
end if
end tell

Note that this line produces a list:

subject of messages of inbox whose read status is false

So you don't need this line:

set theMessages to a reference to every text item of the result as list

When I parse through lists and text in Applescript my preferred tool is the Satimage.osax (url not provided due to technical reasons related to my bleeping domain carrier).  The SIO integrates textual 'find/replace' and regular _expression_ 'find/replace' very neatly into Applescript (amongst many other goodies).

set textToSearch to "
abbot
abbotcy
abbotnullius
abbotship
abbreviate
abbreviately
abbreviation
abbreviator
abbreviatory
abbreviature"

set theResult to find text "abb?.+(n|p).*" in textToSearch ¬
case sensitive false ¬
regexp true ¬
whole word false ¬
all occurrences true ¬
with string result

--> Result:

{
"abbotnullius", 
"abbotship", 
"abbreviation"
}

Something like this is a breeze:

set aList to {"Christopher Stone", "George Wellington", "Christopher Columbus"}

set aList to join aList using linefeed

set theResult to find text ".*chris.*" in aList ¬
case sensitive false ¬
regexp true ¬
whole word false ¬
all occurrences true ¬
with string result

--> Result:

{
"Christopher Stone", 
"Christopher Columbus"
}


You can get pretty fancy and shell out to Perl, Python, Rugy, Tcl, ...

Or you can just use good old-timey unix shell tools like grep:

set textToSearch to "
abbot
abbotcy
abbotnullius
abbotship
abbreviate
abbreviately
abbreviation
abbreviator
abbreviatory
abbreviature"

set searchString to "abbot"
set foundText to do shell script "egrep -i " & searchString & " <<< " & quoted form of textToSearch

--> Result:

"abbot
abbotcy
abbotnullius
abbotship"

--
Chris
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >parsing the results of last night's headache (From: Joshua Whalen <email@hidden>)

  • Prev by Date: Re: How to do a goto with Applescript?
  • Next by Date: Re: How to do a goto with Applescript?
  • Previous by thread: Re: parsing the results of last night's headache
  • Next by thread: Re: parsing the results of last night's headache
  • Index(es):
    • Date
    • Thread