• 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: Help with find text command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with find text command


  • Subject: Re: Help with find text command
  • From: Ed Stockly <email@hidden>
  • Date: Thu, 2 Aug 2007 13:00:28 -0700

William, here's a more complete pure appleScript version that might have some value.

First, your data sample looks pretty ugly, but, when dealing with editorial content, that happens sometimes.

This version only finds 10 digit ISBN formatted numbers. 

One nice thing about using pure appleScript is it would be pretty simple to insert a dialog whenever you come across a suspicious number.

For example, a if you don't have any Russian books in your catalog and your script finds an ISBN number with a code for Russian, you could easily display the number with a few words on either side of it for the user to confirm. From inside InDesign, you could even script a jump to the page and display the word in its context on the page.

HTH,

ES


set AppleScript's text item delimiters to "-"
set OhMyWord to every text item of "
?here is some text with a valid ISBN in it: 0-07-294509-1, and also some
gibbberish with a valid ISBN nestled within it:
fsdfh123@8X452P340-07-294509-2zzzzzz999999. Now that?s bound to cause
trouble.?01-7-294509-x 013-7-94509-X 0139-7-4509-9 013-794-509-8
?here is some text with a valid ISBN in it: 0 -07-294509-7, and also some
gibbberish with a valid ISBN nestled within it:
fsdfh123@8X452P3401-7-294509-x0-07-294509-6zzzzzz999999. Now that?s bound to cause
trouble.?01-7-294509-4 013-7-94509-3 0139-3-4509-2 013-794-509-1"

set x to 2
set foundNumbers to {}
repeat
  set AppleScript's text item delimiters to ""

   repeat

    set pubCode to item x of OhMyWord
    if numberTest(pubCode) then
      set pubCode to pubCode as string
      set pubCodeLength to the count of pubCode
      if pubCodeLength > 7 then exit repeat
    else
      exit repeat
    end if
    set itemNumber to (item (x + 1) of OhMyWord)
    if numberTest(itemNumber) then
      set itemNumberLength to the count of itemNumber
      if itemNumberLength > 7 then exit repeat

    else

      exit repeat
    end if
    set checkSum to character 1 of (item (x + 2) of OhMyWord) as string
    if checkSum is not in "1234567890xX" then exit repeat
    set groupIdLength to 9 - (itemNumberLength + pubCodeLength)
    set groupId to item (x - 1) of OhMyWord
    set firstSize to the count of groupId
    if firstSize < groupIdLength then exit repeat
    if firstSize > groupIdLength then
      set startChar to (groupIdLength)
      set groupId to (items -startChar thru -1 of groupId) as string
    end if
    if numberTest(groupId) then
      set AppleScript's text item delimiters to "-"
      set the end of foundNumbers to {groupId, pubCode, itemNumber, checkSum} as string
      set x to x + 2 
      exit repeat
    else
      exit repeat
    end if
  end repeat
  set x to x + 1
  if x > the ((count of OhMyWord) - 2) then exit repeat
end repeat
return foundNumbers

on numberTest(stringToTest)
  try
    stringToTest as real
    return true
  on error
    return false
  end try
end numberTest

=
 _______________________________________________
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

  • Prev by Date: Re: Script to click on NSStatusItem menu & its submenus
  • Next by Date: Help with applescript creating folders
  • Previous by thread: Re: Help with find text command
  • Next by thread: Re: Help with find text command
  • Index(es):
    • Date
    • Thread