When I execute the code below. I get an error that reads “Finder got an error: Can’t continue FindType. (-1708)”
Any hints on what I can change?
tell application "Finder"
set theFiles to every file of folder "FilesForApp" of desktop
set theTableViewContents to {}
repeat with a from 1 to length of theFiles
set theCurrentFile to item a of theFiles
set theCurrentFileName to name of theCurrentFile
set testType to FindType()
set end of theTableViewContents to {theCurrentFileName, testType, modification date of theCurrentFile}
end repeat
end tell
set content of table view 1 of scroll view 1 of drawer 0 of window "MainWindow" to theTableViewContents
on FindType()
return {do shell script "grep blah blah blah"}
end FindType
To refer to the script’s handler(s) while inside an application-targeted tell block, use my handlerName(.) or handlerName(.) of me. The error message is because the tell app “Finder” context of the call to FindType causes the script to try to tell Finder to run a command called “FindType”.
tell application "Finder" to set theFiles to every file of folder "FilesForApp" of desktop
set theTableViewContents to {}
repeat with theCurrentFile in theFiles
set testType to FindType()
tell theCurrentFile to set end of theTableViewContents to {its name, testType, its modification date}
end repeat
set content of table view 1 of scroll view 1 of drawer 0 of window "MainWindow" to theTableViewContents
on FindType()
return {do shell script "grep blah blah blah"}
end FindType
I finally got a chance to work this out some more and I’m having another issue
Ok so here it is …
This part of the application will look at the contents of a folder and populate a table based on the files in that folder. The part I am having issues with is when I try to do a shell script … I get an error that reads something like:
Can’t make file («class docf» “FirstTest” of «class cfol» “appDB” of «class cfol» “Desktop” of «class cfol» “usejoe” of «class cfol» “Users” of «class sdsk» of application “Finder”) of «script» into type Unicode text. (-1700)
tell application "Finder"
set theFiles to every file of folder "appDB" of desktop
end tell
set theTableViewContents to {}
repeat with a from 1 to length of theFiles
set theCurrentFile to item a of theFiles
set theCurrentFileName to name of theCurrentFile
set foundTestType to my FindType(theCurrentFile)
set testType to foundTestType
set displayedDate to modification date of theCurrentFile
set end of theTableViewContents to {theCurrentFileName, testType, displayedDate}
end repeat
set content of table view 1 of scroll view 1 of drawer 0 of window "mainWindow" to theTableViewContents
on FindType(theCurrentFile)
return (do shell script "grep -w Performed" & space & file theCurrentFile)
end FindType
This is pretty much the last thing I need to figure out before my app is done for now. Any suggestions? Thanks in advance.
the variable theCurrentFile contains a Finder file specifier,
you should coerce it to a path string (or for a shell script the POSIX equivalent),
but I’ m not sure what you’re going to do with the grep line
tell application "Finder"
set theFiles to every file of folder "appDB" of desktop
end tell
set theTableViewContents to {}
repeat with a from 1 to length of theFiles
set theCurrentFile to item a of theFiles
set theCurrentFileName to name of theCurrentFile
set foundTestType to my FindType(POSIX path of (theCurrentFile as text))
set testType to foundTestType
set displayedDate to modification date of theCurrentFile
set end of theTableViewContents to {theCurrentFileName, testType, displayedDate}
end repeat
-- set content of table view 1 of scroll view 1 of drawer 0 of window "mainWindow" to theTableViewContents
on FindType(theCurrentFile)
return (do shell script "grep -w Performed" & space & quoted form of theCurrentFile)
end FindType
I should’ve mention that in my first post. I want the grep line to search for the string “Performed” in theCurrentFile. So as the repeat statement is executed for the length of the files … a grep command is executed each time for each file. Then I want to display the resulting or matching string line inside of the table.
A shell script call in a repeat loop should be avoided if possible.
This script does almost the same, but much faster.
It reports the same result as the shell command
tell application "Finder"
set theFiles to every file of folder "appDB" of desktop
end tell
set theTableViewContents to {}
repeat with a from 1 to length of theFiles
set theCurrentFile to item a of theFiles
set theCurrentFileName to name of theCurrentFile
if (theCurrentFile as text) contains "Performed" then
set displayedDate to modification date of theCurrentFile
set end of theTableViewContents to {theCurrentFileName, "Binary file " & POSIX path of (theCurrentFile as text) & " matches", displayedDate}
end if
end repeat
-- set content of table view 1 of scroll view 1 of drawer 0 of window "mainWindow" to theTableViewContents
hmm just tried compiling the script and the table doesn’t populate at all. I’m gonna dig around a bit and see what’s causing it to stop …
Thanks again StefanK
I included the if - then lines, because I assumed you wanted to display only the files
with contain “performed” (grep filters only the matched items, if there is no match, you get an error message).
Perhaps you describe a bit more detailed, what you’re going to accomplish
Aaaaaaaaahhhhh. Yes, indeed.
How should we know all these things???
Here a smart solution using Spotlight (assuming that the files are indexed)
set theFiles to paragraphs of (do shell script "mdfind -onlyin " & quoted form of ((POSIX path of (path to desktop) & "appDB")) & " kMDItemTextContent = \"Performed:\"")
set theTableViewContents to {}
repeat with theCurrentFile in theFiles
set {name:theCurrentFileName, modification date:displayedDate} to info for (POSIX file theCurrentFile as alias)
set testType to do shell script "cat " & quoted form of theCurrentFile & " | grep -w Performed"
set end of theTableViewContents to {theCurrentFileName, testType, displayedDate as text}
end repeat
set content of table view 1 of scroll view 1 of drawer 0 of window "mainWindow" to theTableViewContents
Hmm wait. I think there is something wrong with the text files I am creating in my app. Your script is correct if I try it with a different text file.
I’ll have to look into this portion. Thanks for the help!