Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Select files by glob
-- get path of Finder window
tell application "Finder"
try
set finder_window to window 1
on error
error "There are no Finder windows"
end try
set start_path to POSIX path of (target of window 1 as alias)
end tell
-- get user input
display dialog "Glob expression" default answer "*.md"
-- get matching files
try
set posix_matches to do shell script "ls -d " & ¬
quoted form of start_path & text returned of result
on error
return
end try
-- convert each path string to alias
set matches to {}
repeat with match in paragraphs of posix_matches
set matches to matches & (POSIX file match)
end repeat
-- select the matches
tell finder_window
activate
select matches
end tell
@olivertaylor

This comment has been minimized.

Copy link

commented Oct 3, 2012

This is great! Any way to make it case-insensitive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.