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 : " ------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------ " ################################################################################################
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.
|