macos shell脚本中的Automator变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4663982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:35:29  来源:igfitidea点击:

Automator Variable in shell script

macosshellunixautomator

提问by switz

Is it possible to pass an Automator variable into a shell script?

是否可以将 Automator 变量传递给 shell 脚本?

采纳答案by mklement0

To complement @Ned Deily's answer:

补充@Ned Deily 的回答

(Written as of OS X 10.9.2, still current as of OSX 10.10)

(从 OS X 10.9.2 开始编写,从 OSX 10.10 开始仍然有效)

It is often notnecessary to create and use explicitvariablesin Automator (using the Set Value of Variableand Get Value of Variableactions).

往往不是必需的创建和使用明确的变量中的Automator(使用Set Value of VariableGet Value of Variable操作)。

The previous action's output is automatically passed to a Run Shell Scriptaction.

上一个动作的输出会自动传递给一个Run Shell Script动作。

By default, the data is passed via stdin, however.

但是,默认情况下,数据通过stdin传递。

If you want it passed as arguments($1, $2, ... - also accessible as an array via $@) instead, select as argumentsfrom the Pass input:list on the right, as illustrated here:

如果您希望将其作为参数传递( $1, $2, ... - 也可通过数组访问$@),请as argumentsPass input:右侧的列表中进行选择,如下所示:

enter image description here

在此处输入图片说明

In this example, the selected Finderitems are passed as POSIX-style pathsto the shell script.

在此示例中,所选Finder项目作为POSIX 样式的路径传递给 shell 脚本。



That said, having a shell script process the data via stdin(using read -rin a loop) works, too:

也就是说,让 shell 脚本通过stdinread -r在循环中使用)处理数据也有效:

enter image description here

在此处输入图片说明

回答by dimpiax

  1. Drag & drop
  2. Store path in filenamevariable
  3. Prompt window for input value in next variable
  4. getfilenamevariable
  5. Store prompt value in rename_to
  6. $1 – rename_tovalue, $2 – filenamevalue
  1. 拖放
  2. 将路径存储在filename变量中
  3. 下一个变量中输入值的提示窗口
  4. 获取filename变量
  5. 将提示值存储在 rename_to
  6. 1 美元 –rename_to价值,2 美元 –filename价值

enter image description here

在此处输入图片说明