【问题标题】:OS X Automator and shell issueOS X Automator 和 shell 问题
【发布时间】:2015-11-23 20:16:59
【问题描述】:

我正在尝试在 OS X 上创建一个自动化工作流程,它会在查找器中打开所选图像并使用 Photoshop 打开它

在此期间,我需要使用 Shell,这是我的代码

# create an empty string
a=""
# grab all the files selected in the finder (given by the previous operation)
for f in "$@"
do
# make a concatenation of the strings
    a=$a" $f"
done
# change the spaces " " by backslash+space "\ "
a=${a//$" "/$"\\ "}
# cut the first two characters
a=${a:2}
# make the full sentence
a="open -a Adobe\ Photoshop\ CC\ 2015 $a"
printf "$a"

最后一个printf的结果是

open -a Adobe\ Photoshop\ CC\ 2015 /Users/me/Downloads/image\ test.jpg

当我将它粘贴到 shell 中时,它可以完美运行,但是当我通过添加运行它时

$a

在我的小脚本中,我有这个问题(字符串被切断)

error screenshot

提前感谢您的帮助:-)

【问题讨论】:

    标签: string macos shell automator


    【解决方案1】:

    不要将数组粉碎成字符串。那就是问题所在。按原样使用数组。

    请参阅Bash FAQ 050 了解字符串化为何存在问题。

    所以只需使用:

    open -a Adobe\ Photoshop\ CC\ 2015 "$@"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-29
      • 2010-11-26
      • 2015-09-24
      • 2011-10-14
      • 1970-01-01
      • 1970-01-01
      • 2016-01-24
      相关资源
      最近更新 更多