• 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: A question on technique
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question on technique


  • Subject: Re: A question on technique
  • From: Olof Hellman <email@hidden>
  • Date: Mon, 16 Mar 2015 19:23:47 -0700


On Mar 16, 2015, at 6:53 PM, Olof Hellman <email@hidden> wrote:


On Mar 16, 2015, at 12:00 PM, email@hidden wrote:

You’ve gotten some good answers here, so this is a bit late, but here are two different approaches.


And here’s a third, using TextEdit app (fairly universally available) as your search engine.  This will scale well for performance if you only need to set up the document once, and query it many times.  


property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470"}
property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}

on setupTextEditDoc()
set allMnemonics to ""
repeat with n from 1 to count Codes
set allMnemonics to allMnemonics & item n of Codes & ", " & item n of Mnemonics & return
end repeat
tell application "TextEdit"
if not (exists document "Mnemonics") then
make new document with properties {name:"Mnemonics"}
end if
set text of document "Mnemonics" to allMnemonics
end tell
end setupTextEditDoc

on MnemonicOf(aCode)
tell application "TextEdit"
set theParagraphs to every paragraph of document "Mnemonics" where it begins with aCode
end tell
return ((characters 7 thru -2 of item 1 of theParagraphs) as text)
end MnemonicOf

setupTextEditDoc()
MnemonicOf("94d0”)


And here’s a fourth, using Excel app as your calculation engine.  This will scale well for very large data sets, again if you only have to set up the document once 



property Codes : {"9420", "94ae", "94d0", "942f", "942C", "9470"}
property Mnemonics : {"RCL", "ENM", "ReW", "EOC", "EDM", "RfW"}

on setupExcelDoc()
tell application "Microsoft Excel"
if not (exists document "Mnemonics") then
set theDoc to make new document with properties {name:"Mnemonics"}
else
set theDoc to document "Mnemonics"
end if

tell worksheet 1 of theDoc
repeat with n from 1 to count Codes
set value of cell 1 of row n to item n of Codes
set value of cell 2 of row n to item n of Mnemonics
end repeat
end tell

end tell
end setupExcelDoc

on MnemonicOf(aCode)
set numRows to count Codes
tell application "Microsoft Excel"
set foundRange to find range ("A1:A" & (numRows as text)) what aCode
set foundRow to first row index of foundRange
return value of cell 2 of row foundRow of worksheet 1 of document "Mnemonics"
end tell
end MnemonicOf

setupExcelDoc()
MnemonicOf("9470")

- Olof


 _______________________________________________
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: A question on technique
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Can I script to add a keyboard shortcut in System Prefs?
  • Next by Date: Re: A question on technique
  • Previous by thread: Re: A question on technique
  • Next by thread: Re: A question on technique
  • Index(es):
    • Date
    • Thread