如何将多个变量从AppleScript传递到Shell脚本? [英] How to pass several variables from AppleScript to Shell script?

查看:122
本文介绍了如何将多个变量从AppleScript传递到Shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Automator执行以下操作:

I use Automator to do the following:

  1. 要求用户选择一个文件夹(作为服务"操作)
  2. 要求用户从列表中选择名称(AppleScript 从列表中选择... )
  3. 将所选文件夹和所选名称传递给shell脚本

我了解如何将在步骤1中选择的文件夹传递给步骤2,但是我不明白如何在步骤2和3之间传递两个变量(我只能传递一个).我在步骤2中尝试返回{answer,input} .但是shell脚本失败,并出现错误-[__ NSArrayM fileSystemRepresentation]:无法识别的选择器发送到实例0x600000654b80 .

I understand how to pass folder chosen from step 1 to step 2. But I don't understand how to pass both variables between steps 2 and 3 (I can pass just one). I tried to return {answer, input} at step 2. But shell-script fails with the error -[__NSArrayM fileSystemRepresentation]: unrecognized selector sent to instance 0x600000654b80.

推荐答案

例如将参数列表传递给shell脚本操作时

When passing the list of parameters to a shell script action for example

return {"/Applications", "com.apple.application-bundle"}

  • $ @ 表示由空格连接的扁平化列表-​​> "/Applications com.apple.application-bundle"
  • $ 1 代表第一个参数-> "/Applications"
  • $ 2 代表第二个参数-> "com.apple.application-bundle"

    • $@ represents the flattened list joined by spaces -> "/Applications com.apple.application-bundle"
    • $1 represents the first parameter -> "/Applications"
    • $2 represents the second parameter -> "com.apple.application-bundle"

      以此类推...

      shell脚本看起来像

      The shell script can look like

      mdfind -onlyin $1 "kMDItemContentType == $2"
      

      注意:确保在外壳程序脚本操作中将参数作为参数传递给 而不是传递给标准输入.

      Note: Make sure that the parameters are passed as arguments rather than to stdin in the shell script action.

      这篇关于如何将多个变量从AppleScript传递到Shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆