Created
June 27, 2023 20:21
-
-
Save tayiorbeii/ee4bf0bd896d86f7f51e8eed74d45a0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import "@johnlindquist/kit" | |
| // Author: Taylor Bell | |
| // Name: search by filename | |
| // Shortcut: opt+f | |
| // Description: Select files in Finder that contain a substring (comma separate for multiple matches) | |
| let searchList = await arg(); // e.g. ".srt, .mp3, taco" | |
| let searchItems = searchList.split(",").map(item => item.trim()).filter(Boolean); | |
| let searchCriteria = searchItems.map(item => `name contains "${item}"`).join(" or "); | |
| await applescript(` | |
| set folderpath to false | |
| tell application id "com.apple.Finder" to tell (a reference to the ¬ | |
| front Finder window) to if it exists then tell its target as ¬ | |
| alias to set folderpath to its POSIX path | |
| if folderpath = false then set folderpath to "~/Desktop" | |
| tell application id "com.apple.SystemEvents" to tell the ¬ | |
| folder named folderpath to tell (every file whose ${searchCriteria}) to set filepaths to its path | |
| tell application id "com.apple.Finder" | |
| reveal the filepaths | |
| activate | |
| return the selection as alias list | |
| end tell | |
| `); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment