[英]Copy files through terminal in Automator
So the following issue seems to be caused within Automator but I cannot be sure (I would post an image but I don't have enough points): 因此,以下问题似乎是由Automator引起的,但我不确定(我会发布图像,但积分不足):
I have an Automator service whose first action is “Get Specified Finder Items” tool that goes to ~/Desktop/D53_C71J_C
. 我有一个Automator服务,其第一个操作是转到~/Desktop/D53_C71J_C
“获取指定的查找器项目”工具。 The next action is a “Run Shell Script” containing 下一个动作是“ Run Shell Script”,其中包含
PATH="$@"
echo "Path: $PATH"
cd "$PATH"
for f in *;
do
echo "f: $f"
CAT="$PATH/$f"
echo "CAT: $CAT"
cp "$f" ~/Desktop
done
The results are 结果是
Path: /Users/ajharn/Desktop/D53_C71J_C
f: D53_C71J_C1.psd
CAT: /Users/ajharn/Desktop/D53_C71J_C/D53_C71J_C1.psd
f: D53_C71J_C1_MERGE.psd
CAT: /Users/ajharn/Desktop/D53_C71J_C/D53_C71J_C1_MERGE.psd
f: D53_C71J_C2.psd
etc. It all works until it gets to cp
. 等等,直到到达cp
为止,所有方法都有效。 I've tested with echos and such and paths are lined up. 我已经测试过回声,并且这样和路径都对齐了。 The confusing part is that cp D53_C71J_C2.psd ~/Desktop
works fine in Terminal. 令人困惑的部分是cp D53_C71J_C2.psd ~/Desktop
在Terminal中可以正常工作。
You have chosen your variable name very unwisely: PATH
is used by the shell to store the path to directories where executables are located (see the section on special shell parameters in the BashGuide and the bash man page ). 您非常不明智地选择了变量名:shell使用PATH
将路径存储到可执行文件所在的目录(请参阅BashGuide和bash手册页中 有关特殊shell参数的部分 )。 As cp
is an external program, not a shell command (it is found at /bin/cp
), it is not found by the shell when you overwrite PATH
with your current working path – and thus never runs. 由于cp
是一个外部程序,而不是shell命令(可在/bin/cp
),因此当您用当前的工作路径覆盖PATH
时,shell不会找到它-因此它永远不会运行。
Do something more along the lines of 按照以下方式做更多事情
[[ -d "$@" ]] && cd "$@" # cd into folder if is one
for f in ./*; do # always prefix relative globs
[[ -f "$f" ]] && cp "$f" ~/Desktop # only copy files
done
and all will be well. 一切都会好起来的。 Of course, adding a “Get Folder Contents” action and a “Move Finder Objects” one will work too, without any shell intervention. 当然,添加“获取文件夹内容”操作和“移动查找器对象”操作也将起作用,而无需任何shell干预。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.