Re: Search strings from a file
Re: Search strings from a file
- Subject: Re: Search strings from a file
- From: "Marc K. Myers" <email@hidden>
- Date: Tue, 18 Sep 2001 16:46:39 -0400
- Organization: [very little]
>
Date: Tue, 18 Sep 2001 10:31:52 -0400 (EDT)
>
From: Greg Sutherland <email@hidden>
>
To: email@hidden
>
Subject: Re: applescript-users digest, Vol 2 #1070 - 16 msgs
>
>
I got the following script from Marc Myers. It works just fine, but I
>
want to get the strings from a list rather than prompt for them. I can
>
create a list and do a repeat with the items, but I don't know how to get
>
items of the correct type to work in the statement
>
>
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, text returned of theRslt}
>
>
I know that the problem is that my list is type text, but I can't find any
>
documentation or examples to help with this.
>
>
TIA, greg
>
>
set theFile to (choose file with prompt "Pick the file to analyze:" of type {"TEXT"})
>
set theRslt to (display dialog "Enter the string whose occurrences you want to count:" default answer "")
>
set fileID to (open for access theFile)
>
try
>
set theText to (read fileID)
>
close access fileID
>
on error m number n
>
try
>
close access fileID
>
end try
>
error m number n
>
end try
>
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, text returned of theRslt}
>
set theCount to (count text items of theText) - 1
>
set AppleScript's text item delimiters to od
>
display dialog "The string occurred " & (theCount as text) & " time(s)" buttons {"OK"} default button 1
I lost the original name of this thread. Oh well...
set theFile to (choose file with prompt "Pick the file to " & [optn-L]
"analyze:" of type {"TEXT"})
set fileID to (open for access theFile)
try
set theText to (read fileID)
close access fileID
on error m number n
try
close access fileID
end try
error m number n
end try
set theFile to (choose file with prompt "Pick the file of search " & [optn-L]
"strings:" of type {"TEXT"})
set fileID to (open for access theFile)
try
set srchTbl to (read fileID as {text} using delimiter {return})
close access fileID
on error m number n
try
close access fileID
end try
error m number n
end try
set rsltText to ""
set od to AppleScript's text item delimiters
repeat with srchStrng in srchTbl
set AppleScript's text item delimiters to srchStrng
set theCount to (count text items of theText) - 1
set rsltText to rsltText & srchStrng & tab & (theCount as text) & return
end repeat
set AppleScript's text item delimiters to od
set fileID to (open for access file ((path to desktop as text) & [optn-L]
"Search Log") with write permission)
try
set eof fileID to 0
write rsltText to fileID
close access fileID
on error m number n
try
close access fileID
end try
error m number n
end try
This version reads in the search strings from a text file with one
search string in each line. It reads them into a table. The table gets
stepped through to do the searches and the results are concatenated to a
text variable. Finally, the text variable is written to a text file.
Don't forget to replace "[optn-L]" with the AppleScript continuation character.
Marc K. Myers <email@hidden>
http://AppleScriptsToGo.com
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074
[9/18/01 4:45:35 PM]