• 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: Checking a Record for a Field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking a Record for a Field


  • Subject: Re: Checking a Record for a Field
  • From: Yvan KOENIG <email@hidden>
  • Date: Mon, 16 Nov 2015 21:25:16 +0100


Le 2015/11/16 à 18:21, Christopher Stone <email@hidden> a écrit :

On Nov 16, 2015, at 08:17, S. J. Cunningham <email@hidden> wrote:
I have a handler  to which I would like to pass a variable number of arguments.  I am using a record to pass the arguments and then checking in the handler whether or not a specific field exists so I can skip it if it doesn't.
______________________________________________________________________

Hey Steve,

The hackish way to handle that:

set theRecord to {Field_1:"Field 1", Field_2:"Field 2"}

try
  theRecord / 0
on error eMsg
  set AppleScript's text item delimiters to {"{", "}"}
  set checkRecord to text item 2 of eMsg
end try

set AppleScript's text item delimiters to ":"

set fieldName to text item 1 of checkRecord
set s to fieldName & " of {" & checkRecord & "}"
run script s

I believe there's an ASObjC method to extract the keys directly.

--
Best Regards,
Chris


Maybe this enhanced version may help.

set theRecord to {Field_1:"Field 1", Field_3:"Field 3"}

try
theRecord / 0
on error eMsg
log eMsg
set AppleScript's text item delimiters to {"{", "}"}
set checkRecord to text item 2 of eMsg
end try
log checkRecord
set AppleScript's text item delimiters to {":", ", "}
set fieldsNames to {}
set fieldsValues to {}
set i to 1
repeat
try
set fieldName to text item i of checkRecord
set end of fieldsNames to fieldName
set s to fieldName & " of {" & checkRecord & "}"
set end of fieldsValues to run script s
set i to i + 2
on error
exit repeat
end try
end repeat
log fieldsNames (*Field_1, Field_3*)
log fieldsValues (*Field 1, Field 3*)

As you see, it return the list of fieldsNames available in the record and a list of their values.


Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) lundi 16 novembre 2015 21:25:10


 _______________________________________________
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: 
 >Checking a Record for a Field (From: "S. J. Cunningham" <email@hidden>)
 >Re: Checking a Record for a Field (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Checking a Record for a Field
  • Next by Date: Re: Checking a Record for a Field
  • Previous by thread: Re: Checking a Record for a Field
  • Next by thread: Re: Checking a Record for a Field
  • Index(es):
    • Date
    • Thread