• 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
Look-Up-Table (was Re: Convert Text to Variable Name)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Look-Up-Table (was Re: Convert Text to Variable Name)


  • Subject: Look-Up-Table (was Re: Convert Text to Variable Name)
  • From: Christopher Stone <email@hidden>
  • Date: Mon, 17 Jan 2011 15:35:05 -0600

On Jan 17, 2011, at 14:16, Skeeve wrote:
It seems to me there's a way to convert text to a declared variable name, but I can't remember how.
I do not think it is a good idea to use "run script".
______________________________________________________________________

Hey Folks,

When I posted originally I was just toying with some ideas to make a different look-up-table and get reacquainted with some of the funky things one can do with script objects.

For the purposes of the script I'm writing now I want a lookup-table that can be easily maintained as a text file outside of the script.  The script will check the modification date of the file and reload it as necessary.

For this sort of lookup I usually use the Satimage.osax, but I'll post a more portable Ruby example here:

################################################################################################
# ccs
# Working LookUpTable using Ruby Regular Expressions
# 2011-01-15 : 11:55
# Pulled the Lookup-Table out of the Ruby Command String
# Using Apple Character as a Delimiter
################################################################################################
property lookupTableString : "
------------------------------------------------------------------------------------------------
email@hidden                                                                 Hey Mark,
email@hidden, email@hidden                                          Hey John,
email@hidden                                                               Hey John,
email@hidden                                                                 Hey Tobe,
email@hidden                                                               Hey Dennis,
email@hidden                                                                 Hey Wade,
------------------------------------------------------------------------------------------------
"
################################################################################################

set regexStr to "email@hidden[^]+\\s+([^ ]+ [^ ]+)$"

set shellCmdString to "/usr/bin/ruby -e'
target_string = \"" & lookupTableString & "\"
puts /" & regexStr & "/i.match(target_string)[1]'"

try
set lookupResult to do shell script shellCmdString
on error errMsg number errNum
"Error: " & errMsg & return & "Error Number: " & errNum
end try
################################################################################################

I've done this sort of thing many times over the years (since the very first regular expressions osax arrived on the scene), and these days I prefer the Satimage.osax for speed, power, simplicity, and complete integration with Applescript.  However I've written similar systems using the shell 'egrep', and I'm interested in further expanding my repertoire to Perl, Python, and perhaps TCL.  (At the moment I don't know enough Ruby to even be dangerous, but I'm working on it. :)

Script Debugger will run this snippet in about 0.015 seconds on my machine, and if I extend the table data to 2460 lines it will still run in about 0.065 seconds.  Any more data and it craps out, which I assume is a limitation of the do shell script mechanism.

I expect there's a nice way to write it so it takes input from a file, so if someone knows how to do that I'd be grateful for the lesson.

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

  • Follow-Ups:
    • Re: Look-Up-Table (was Re: Convert Text to Variable Name)
      • From: Philip Ershler <email@hidden>
References: 
 >Convert Text to Variable Name (From: Christopher Stone <email@hidden>)
 >Re: Convert Text to Variable Name (From: Skeeve <email@hidden>)

  • Prev by Date: Re: AppleScript-Users Digest, Vol 8, Issue 44
  • Next by Date: Re: Look-Up-Table (was Re: Convert Text to Variable Name)
  • Previous by thread: Re: Convert Text to Variable Name
  • Next by thread: Re: Look-Up-Table (was Re: Convert Text to Variable Name)
  • Index(es):
    • Date
    • Thread