如何在Automator Shell脚本中使用空格的路径?

发布于 2025-02-02 02:54:10 字数 781 浏览 3 评论 0原文

我有一个Automator工作流程,该工作流程应将所选文件的创建日期设置为我要输入的日期。不幸的是,我的道路有空间。因此,它不起作用。 我尝试了几种变体,例如:

SetFile -d \"$1 12:00:00\" "$@2"
SetFile -d \"$1 12:00:00\" \"$@2\"
SetFile -d \"$1 12:00:00\" '$@2'
SetFile -d \"$1 12:00:00\" \'$@2\'

这条路就像以下内容: /users/simon/documents/steuern/steuern 2021/scan_000775.pdf

我使用的外壳是ZSH,安装了OH-MY-ZSH。

这是我拥有的工作流程:

  • 询问finder -object
  • get guet of variable
  • 询问文本输入
  • 集值的变量
  • 询问可变
  • execute shell脚本的值:“ setFile -d” $ 1 12:00:00:$ 1 12:00:00“ $@2” “

任何人都可以告诉我如何编写ShellScript以将路径名与空格使用? 那会很好。谢谢。

I have an Automator workflow which should set the CreationDate of the selected file to a date which I want to enter. Unfortunately my path have spaces. Therefore it doesn'w work.
I've tried several variants like:

SetFile -d \"$1 12:00:00\" "$@2"
SetFile -d \"$1 12:00:00\" \"$@2\"
SetFile -d \"$1 12:00:00\" '$@2'
SetFile -d \"$1 12:00:00\" \'$@2\'

The path is like follows:
/Users/simon/Documents/Steuern/Steuern 2021/Scan_000775.pdf

The shell I use is ZSH with oh-my-zsh installed.

This is the Workflow I have:

  • Ask for Finder-Object
  • Get value of variable
  • Ask for Text input
  • Set value of variable
  • Ask for value of variable
  • execute shell script: "SetFile -d "$1 12:00:00" "$@2""

enter image description here

Can anyone tell me how to write the shellscript to use pathnames with spaces?
That would be very nice. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2025-02-09 02:54:10

如果我理解正确,您想要:

SetFile -d "$1 12:00:00" "${@:2}"

解释:逃脱的引号会阻止它们像引号一样行动(它将它们变成了正常的字符);在这种情况下,您希望它们充当报价,因此您不应该逃脱它们。另外,“ $@2”没有从$ 2开始获得参数,它得到了参数的全部,并粘贴一个“ 2 “到最后一个。如果您需要除第一个的所有参数,请使用“ $ {@:2}”而不是。

If I'm understanding right, you want:

SetFile -d "$1 12:00:00" "${@:2}"

Explanation: escaping quotes prevents them from acting like quotes (it turns them into normal characters); in this case, you want them to function as quotes, so you shouldn't escape them. Also, "$@2" doesn't get the arguments starting at $2, it gets all of the arguments, and sticks a "2" to the end of the last one. If you want all the arguments except the first, use "${@:2}" instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文