• 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: Creating a list of numbers from a Contacts group
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a list of numbers from a Contacts group


  • Subject: Re: Creating a list of numbers from a Contacts group
  • From: Yvan KOENIG <email@hidden>
  • Date: Thu, 05 Jan 2017 21:40:47 +0100


Le 5 janv. 2017 à 20:50, Steve Mills <email@hidden> a écrit :

On Jan 05, 2017, at 01:20 PM, debt <email@hidden> wrote:

On Jan 5, 2017, at 10:53 AM, Steve Mills <email@hidden> wrote:
That's correct. "e" is the error string that resulting from the div by zero. He's just being a showoff. :) Here's a more AppleScripty way of doing it. It replaces the entire try/on error block:

set phoneNumList to phoneNumList as text
set text item delimiters to {","}
set phoneNumList to every text item of phoneNumList

I tried your version but it destroys the list, so Chris may actually be on to something with the try block. :)

Sorry, the delimiters were already set to a non-default value before I ran it, so it worked. If you really want to learn how to do this with AppleScript, experiment and don't use error message hacks (whose content can sure change on a whim of some future update) or Unix commands unless there really is no other way. This'll do it:

set tid to text item delimiters
set text item delimiters to {return}
set phoneNumList to (phoneNumList as text)
repeat while phoneNumList contains return & return
set text item delimiters to {return & return}
set phoneNumList to every text item of phoneNumList
set text item delimiters to {return}
set phoneNumList to phoneNumList as text
end repeat
set text item delimiters to {return}
if last character of phoneNumList is return then set phoneNumList to text 1 thru -2 of phoneNumList
set phoneNumList to every text item of phoneNumList
set text item delimiters to tid

You may shorten your code :
-------------------------------------------------------------------------------------------
tell application "Contacts"
tell group "Famille"
set phoneNumList to value of every phone of every person
end tell
end tell

set tid to text item delimiters
set text item delimiters to {return}
set phoneNumList to (phoneNumList as text)
repeat while phoneNumList contains return & return
set text item delimiters to {return & return}
set phoneNumList to every text item of phoneNumList
set text item delimiters to {return}
set phoneNumList to phoneNumList as text
end repeat
set text item delimiters to tid
if last character of phoneNumList is return then set phoneNumList to text 1 thru -2 of phoneNumList

set phoneNumList to paragraphs of phoneNumList
-------------------------------------------------------------------------------------------
I really wish there was a way to filter lists directly in AppleScript. Like why can't this work:

set blah to {"one","","two"}
set blah to every item of blah where it is not ""
-->{"one","two"}

That would make this script so much shorter. Or even:

tell application "Contacts"
tell group "Family"

set phoneNumList to value of every phone of (every person whose phones is not {})
end tell

end tell

ASObjC offers this kind of feature.

-------------------------------------------------------------------------------------------
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions

on deleteItem:anItem fromList:theList
set theArray to current application's NSMutableArray's arrayWithArray:theList
theArray's removeObject:anItem
set unionOfArrays to (theArray's valueForKeyPath:"@unionOfArrays.self") as list
return unionOfArrays
end deleteItem:fromList:

tell application "Contacts"
tell group "Famille"
set phoneNumList to value of every phone of every person
end tell
end tell
set phoneNumList to its deleteItem:{} fromList:phoneNumList
-------------------------------------------------------------------------------------------

Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) jeudi 5 janvier 2017 21:40:22


 _______________________________________________
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

  • Follow-Ups:
    • Re: Creating a list of numbers from a Contacts group
      • From: debt <email@hidden>
References: 
 >Re: Creating a list of numbers from a Contacts group (From: Steve Mills <email@hidden>)

  • Prev by Date: Re: Creating a list of numbers from a Contacts group
  • Next by Date: Re: Creating a list of numbers from a Contacts group
  • Previous by thread: Re: Creating a list of numbers from a Contacts group
  • Next by thread: Re: Creating a list of numbers from a Contacts group
  • Index(es):
    • Date
    • Thread