I am accustomed to store my scripts as .applescript files stored in subfolders of a dedicated folder so, when I need to search for a string in them I use the free Easyfind which return very quickly the list of files containing the searched string.
The only feature which is missing - from my point of view - is the fact that we can’t copy the returned list. When I copy it, the clipboard contain icons but say that it doesn’t contain text datas.
I use GUI scripting to extract the useful infos:
set targetFile to (path to desktop as text) & "filesFound.txt"
tell application "System Events" to tell process "EasyFind"
set frontmost to true
tell window 1
--class of UI elements --> {button, button, button, scroll area, button, checkbox, checkbox, checkbox, radio group, radio group, checkbox, checkbox, static text, static text, static text, static text, text field, menu button, static text, list, toolbar, static text}
select row 1 of table 1 of scroll area 1 # reveal the list of path components
set folderName to name of menu button 1 --> "des scripts"
--class of UI elements
set theItems to value of attribute "AXChildren" of list 1
set pathComponents to {}
repeat with i from 1 to 1000 # a fake value
set aComponent to value of item i of theItems
set end of pathComponents to aComponent
if aComponent = folderName then exit repeat
end repeat
set begOfPath to "/Users/" & my recolle(pathComponents, "/")
# Here, begOfPath is: "/Users/my user name/Documents/mon bureau/des scripts"
my writeto(targetFile, begOfPath & linefeed, «class utf8», false) # create the report file
tell scroll area 1
--class of UI elements --> {table, scroll bar}
tell table 1
--class of UI elements --> {row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, column, column, column, column, column, column, group}
set nbr to count rows
set theInfos to {}
repeat with i from 1 to nbr
tell row i
--class of UI elements --> {static text, static text, static text, text field, text field, static text}
set fName to value of static text 1
if fName ends with ".applescript" then my writeto(targetFile, fName & tab & value of static text -1 & linefeed, «class utf8», true)
end tell
end repeat
end tell
end tell
end tell
end tell
#=====
on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle
#=====
(*
Handler borrowed to Regulus6633 - http://macscripter.net/viewtopic.php?id=36861
*)
on writeto(targetFile, theData, dataType, apendData)
-- targetFile is the path to the file you want to write
-- theData is the data you want in the file.
-- dataType is the data type of theData and it can be text, list, record etc.
-- apendData is true to append theData to the end of the current contents of the file or false to overwrite it
try
set targetFile to targetFile as «class furl»
set openFile to open for access targetFile with write permission
if not apendData then set eof of openFile to 0
write theData to openFile starting at eof as dataType
close access openFile
return true
on error
try
close access file targetFile
end try
return false
end try
end writeto
#=====
It’s slow but it return a file containing the list of the filenames and the partial path of these files in the target folder whose path is stored ain the first line of the document.
Maybe it may help others.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 13 novembre 2019 19:29:06