I am trying to create a macro to highlight multiple files in a Finder window? I tried using the reveal action but I could only highlight a single file.
How do I highlight multiple filenames in the Downloads folder, each name on a list separated by a line break?
Hey Mirizzi,
If you have verbatim file names then an AppleScript like this will work:
set myFileNames to text 2 thru -2 of "
test_file_004.txt
test_file_012.txt
test_file_021.txt
"
set targetFolderPath to path to downloads folder as text
set myFilePaths to paragraphs of myFileNames
repeat with i in myFilePaths
set contents of i to alias (targetFolderPath & contents of i)
end repeat
tell application "Finder"
open folder targetFolderPath
tell front window
select myFilePaths
end tell
end tell
-Chris
Thanks a million. That was really fast.
Edited: I noticed and corrected an error due to an empty line in my file list causing 2 Finder windows to open.
Hey Mirizzi,
That's why the text 2 thru -2
line was in there to remove line breaks at top and bottom.
But let's go ahead and make that more fault-tolerent shall we?
This version will dispose of all extraneous line breaks.
----------------------------------------------------
set myFileNames to "
test_file_004.txt
test_file_012.txt
test_file_021.txt
"
set targetFolderPath to path to downloads folder as text
set aliasList to paragraphs of myFileNames
repeat with i in aliasList
set iAsStr to contents of i
if iAsStr is "" then
set contents of i to missing value
else
set contents of i to alias (targetFolderPath & iAsStr)
end if
end repeat
set aliasList to aliases of aliasList
if aliasList ≠ {} then
tell application "Finder"
open folder targetFolderPath
tell front window to select aliasList
end tell
end if
----------------------------------------------------
When I write this sort of thing for myself I use the [Satimage.osax][1]’s find text command with regexp, because it gives me more precise control over what I'm grabbing from a text-table.
----------------------------------------------------
# REQUIRES SATIMAGE.OSAX http://tinyurl.com/dc3soh
----------------------------------------------------
set myFileNames to "
test_file_004.txt
test_file_012.txt
test_file_021.txt
"
set targetFolderPath to path to downloads folder as text
set aliasList to find text "^(\\w.+)" in myFileNames using (targetFolderPath & "\\1") ¬
with regexp, all occurrences and string result
if aliasList ≠ {} then
repeat with i in aliasList
set contents of i to i as alias
end repeat
tell application "Finder"
open folder targetFolderPath
tell front window to select aliasList
end tell
end if
----------------------------------------------------
Then again there are easier ways yet using the Satimage.osax. ``` ---------------------------------------------------- # REQUIRES SATIMAGE.OSAX http://tinyurl.com/dc3soh ---------------------------------------------------- set fileNameList to "
test_file_004.txt
test_file_012.txt
test_file_021.txt
"
set targetFolderPath to path to downloads folder
set aliasList to glob (find text "^\w.+" in fileNameList with regexp, all occurrences and string result) ¬
from targetFolderPath as alias
if aliasList ≠ {} then
tell application "Finder"
open targetFolderPath
tell front window to select aliasList
end tell
end if
-Chris
[1]: http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html
[2]: http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html