将操作分配给Automator中的变量以在Shell脚本中使用 [英] Assign action to variable in Automator for use in Shell Script

查看:371
本文介绍了将操作分配给Automator中的变量以在Shell脚本中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这件事现在让我发疯.因此,操作1选择一个文件夹(我想将该文件夹的路径另存为var_1),操作3选择一个文件(我想将该文件的路径另存为var_2)

Ok, this thing is driving me crazy right now. So Action 1 Chooses a Folder (I want to save that folder's path as var_1) and Action 3 Selects a File (I want to save this file's path as var_2)

所以最后. . .

var_1 = '/Users/Prometheus/Desktop/'
var_2 = '/Users/Prometheus/Documents/a.txt'

那我如何在python的Shell Script中使用这些变量及其值?我不能使用sys.argv,因为它们被设置为一些奇怪的变量

So how do I use these variables and their values inside of Shell Script with python ? I can't use sys.argv because they are set to some weird variables

我通常将询问查找器项目">运行Shell脚本",然后

I usually put 'Ask for Finder Item' > Run Shell Script and then

import sys

variable = open(argv[1]).read()

但是在这种情况下我不能使用它.我的脚本使用的是python,所以我宁愿留在python中,因为我不知道其他任何语言

but i can't use that in this case . my scripts are in python so i'd rather stay in python because i don't know any other language

推荐答案

Automator变量仅在Automator工作流程中使用. Shell脚本或Python脚本不能直接访问变量本身. Run Shell Script操作允许您通过以下两种方式之一将特定变量的值传递给Shell脚本:通过stdin用管道传递它们或通过将它们作为执行参数传递.对于这种用例,后者更容易.首先,您需要在Set Value of VariableGet Value of Variable操作中选择Automator变量名称,以便可以在操作之间保留所选的值.这是一个非常基本的工作流程示例,其中我选择了两个文件夹:

The Automator variables are only used in the Automator workflow. The variable themselves are not directly accessible to either a shell script or a Python script. The Run Shell Script action allows you to pass the values of particular variables to a shell script in either of two ways: either piping them in through stdin or by passing them as execution arguments. For this sort of use case, the latter is easier. To start with, you need to pick Automator variable names in the Set Value of Variable and Get Value of Variable actions so the values selected can be retained between actions. Here's a very rudimentary workflow example where I've selected two folders:

这篇关于将操作分配给Automator中的变量以在Shell脚本中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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