简体   繁体   中英

Automator Variable in shell script

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

To complement @Ned Deily's answer :

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

It is often not necessary to create and use explicit variables in Automator (using the Set Value of Variable and Get Value of Variable actions).

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

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

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

在此输入图像描述

In this example, the selected Finder items are passed as POSIX-style paths to the shell script.


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

在此输入图像描述

  1. Drag & drop
  2. Store path in filename variable
  3. Prompt window for input value in next variable
  4. get filename variable
  5. Store prompt value in rename_to
  6. $1 – rename_to value, $2 – filename value

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM