• 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: Look for prefix, if no match display alert.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Look for prefix, if no match display alert.


  • Subject: Re: Look for prefix, if no match display alert.
  • From: Adam Bell <email@hidden>
  • Date: Mon, 28 Aug 2006 20:12:06 -0300

Title: Re: Look for prefix, if no match display alert.
At 11:32 AM +0200 8/28/06, Jan Bultereys wrote (in part):

But my script is still going to be big if I want to "compare" all the variables.
Ideally would be compare prefix of 'page name" if prefixes are present that are not the same as the first 3 digit of the "page name" AND are present in the "to check prefix list" then give a message.

The problem I am facing right now is if I use
example: set counter to count (every word where it = prefix)
The quark will give an error since it is not able to count prefixes that are not existing....

Best regards,jan

Jan;

Everything has to be driven by general code. I don't have Quark, but this is an example of how you should proceed:

property prefix : missing value

set prefix to setPrefix() -- done only once
-- then for each text sample grabbed from QE (the sample below is just to have something to test):
set sample to "YF7 This is an item using AF9, see photo AF9 and YFN"

set head to text 1 thru 3 of sample -- get first three letters of text
set msgs to ChkSample(sample, head) -- go to handlers to do the deed
displayMessage(msgs, head) -- display the result for one sample (this will slow you down immensely)

-- handlers

-- This is a slight variation on what I sent to the list earlier
to setPrefix()
       set {GF, AF, YF, KF} to {{}, {}, {}, {}} -- set up holders
      copy {GF, AF, YF, KF} to group -- get a conventient way to refer to them by index
       set len to {9, 12, 12, 12} -- the number of prefixes in each class
      set family to {"GF", "AF", "YF", "KF"} -- the classes of prefix
set pNum to "123456789DHN" -- the adders to the family members
  set Prefixes to "" -- to hold the list of prefixes
      repeat with j from 1 to 4 -- iterate through the families
               set fam to family's item j
              set grp to group's item j
               repeat with k from 1 to len's item j -- stick on the adders
                     set Prefixes to Prefixes & fam & character k of pNum & space
            end repeat
      end repeat
      return Prefixes -- a string of all prefixes separated by spaces
end setPrefix
-- This one actually does the checking and counting. It only runs through the entire text if the text contains the prefix being checked - otherwise it just goes on to the next.
to ChkSample(sample, head)
        set srch to my getChkList(head) -- see it below - we only do this once per sample
        set preCounts to {} -- a holder for the answer
  repeat with pre in srch
        if sample contains contents of pre then -- go on if there aren't any
                    set tid to AppleScript's text item delimiters
                   set AppleScript's text item delimiters to contents of pre -- separate out
                       set c to count text items of sample -- count them
                       set AppleScript's text item delimiters to tid
                   set end of preCounts to c - 1 & "copies of " & pre -- prepare part of message
           end if
  end repeat
      return preCounts -- a list of messages
end ChkSample
-- This handler prepares a new list of prefixes that excludes the the leading one for the text. Doing it once this way is faster than an if statement in every loop.
to getChkList(head)
set tid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to head
  set p to text items of prefix
   set AppleScript's text item delimiters to tid
   set srchPrefixes to words of (p as text)
        return srchPrefixes
end getChkList

to displayMessage(aList, aPre)
if aList = {} then
              display dialog "The sample with head " & aPre & " is clean"
     else
            set leader to "This sample with head " & aPre & " has"
          repeat with M in aList
                  set leader to leader & return & M
               end repeat
              display dialog leader
   end if
end displayMessage





 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Look for prefix, if no match display alert. (From: Jan Bultereys <email@hidden>)

  • Prev by Date: XML Suite in System Events
  • Next by Date: Re: Dialog from script application displays raw codes (was: no subject)
  • Previous by thread: Re: Look for prefix, if no match display alert.
  • Next by thread: Re: Look for prefix, if no match display alert.
  • Index(es):
    • Date
    • Thread