从选择在 Finder 中搜索 [英] Searching in Finder from Selection

查看:26
本文介绍了从选择在 Finder 中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常我会得到一个包含数十个文件名的 Excel 电子表格,然后我需要单独搜索这些文件.

Usually I get an excel spreadsheet with dozens of filenames, for which I then need to go and search individually.

Spreadhseet

有没有办法让我可以简单地:

Is there a way that I could simply:

  1. 选择所有文件名,例如A 行 Excel,
  2. 然后在This Mac"
  3. 上搜索所有这些文件
  4. 然后将所有找到的文件复制到桌面
  5. 上的新建文件夹

到目前为止,我已经尝试了搜索的第一部分,这就是我得到的 :a)

So far I've tried the first part of searching and this is what i get :a)

带变量的自动机.但问题是,它只从选择中搜索 1 个文件

b)

Automator with Shell Script(复制到剪贴板 > 打开 Finder > CMD+F(突出显示搜索)对话框)> CMD+V).它会打开一个新的 Finder 窗口,但不会将剪贴板粘贴到搜索对话框中

c) /usr/bin/pbcopy

on run {input, parameters}
    tell application "System Events"
        keystroke "f" using {command down}
        keystroke "v" using {command down}
    end tell    
    return input
end run`

最终结果,与选项 b) 相同.我计划在 Automator 中将其作为Service"运行,稍后我可以将其分配给键盘快捷键.

End result, is same as option b). I was planning to run this in Automator as a 'Service', which I could later assign to Keyboard Shortcut.

我很确定应该有一个简单的 shell 选项 - 任何建议都将不胜感激.

I am pretty sure there should be a simple shell option for this - any advice would be much appreciated.

推荐答案

我制作了一个 bash 脚本来执行您想要的操作.您基本上可以在 Excel 或任何其他应用程序中选择一堆文件名,然后使用 C 将它们复制到剪贴板.之后,您需要运行脚本,它将从剪贴板中获取项目并搜索与该名称匹配的 TIFF 或 JPEG 图像,并将它们复制到桌面上名为 Selected Files 的目录:

I made a bash script that does what you want. You would basically select a bunch of filenames in Excel, or any other app, and copy them to the clipboard with C. After that you need to run the script and it will take items from the clipboard and search for TIFF or JPEG images that match that name and copy them to a directory on your Desktop called Selected Files:

#!/bin/bash

# Get contents of clipboard into bash array
files=( $(pbpaste) )

# Create output directory - no checks for already existing or already containing files
OUTDIR="$HOME/Desktop/Selected Files"
mkdir -p "$OUTDIR"

# Iterate through fetching files
for ((i=0;i<${#files[@]};i++)) ; do
   name=${files[i]}
   result=$( mdfind "kMDItemDisplayName == \"${name}.*\" && (kMDItemKind==\"TIFF image\" || kMDItemKind==\"JPEG image\")" )
   if [ -f "$result" ]; then
      echo $name: $result
      cp "$result" "$OUTDIR"
   else
      echo ERROR: Searched for: $name, found $result
   fi
done

<小时>

我不确定您对 bash 的熟悉程度,因此您可以忽略以下内容...


I am not sure of your level of familiarity with bash, so you may be able to ignore the following...

为您自己的脚本创建一个新目录:

Make a new directory for your own scripts:

mkdir -p $HOME/scripts

使用文件名将上述脚本保存在该目录中:

Save the above script in that directory with filename:

$HOME/scripts/gather

通过在终端中输入以下内容使脚本可执行:

Make the script executable by typing this into Terminal:

chmod +x $HOME/scripts/gather

编辑您的登录配置文件 ($HOME/.profile) 并将您的 $HOME/scripts 目录添加到您的路径:

Edit your login profile ($HOME/.profile) and add your $HOME/scripts directory to your PATH:

export PATH="$PATH":$HOME/scripts

然后启动一个新的终端,您可以使用保存在$HOME/scripts中的任何脚本,而无需指定其完整路径,例如:

Then start a new Terminal and you can use any script that you have saved in $HOME/scripts without needing to specify the full path to it, e.g.:

gather

<小时>

以下信息由@user3439894 在评论部分提供,因为我对这方面的深度不够...


Following information kindly contributed by @user3439894 in comments section, as I am out of my depth on this aspect...

要使用键盘快捷键,您必须创建一个 Automator 服务工作流",并带有 运行 Shell 脚本" 操作,您可以为其分配键盘快捷键:系统偏好设置 > 键盘 > 快捷方式 > 服务

To use a keyboard shortcut, you'd have to create an Automator "Service workflow" with a "Run Shell Script" action, which you can assign a keyboard shortcut to under: System Preferences > Keyboard > Shortcuts > Services

这篇关于从选择在 Finder 中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆