macos Automator:如何使用“从列表中选择”操作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11440062/
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
Automator: How do I use the Choose from List action?
提问by bmauter
I'm trying to create a Service using Automator that simply calls textutil convert. Eventually, I want to be able to right-click a docx file and convert to text, rtf, html, etc. After I right-click I want a very simple popup asking for the desired format.
我正在尝试使用 Automator 创建一个简单地调用 textutil convert 的服务。最后,我希望能够右键单击 docx 文件并转换为文本、rtf、html 等。在我右键单击后,我想要一个非常简单的弹出窗口,询问所需的格式。
I see the Choose from List action. It has no options. Somewhere I got the idea to make the input of Choose from List be Get Specified Text. I then tried putting my list of values in Get Specified Text. However, when I run it, I only get one line. I've tried one item per line, comma-delimited, space-delimited and even surrounding with curly braces, delimited with commas. Nothing works.
我看到“从列表中选择”操作。它没有选择。在某处我想到了让从列表中选择的输入成为获取指定文本的想法。然后我尝试将我的值列表放在获取指定文本中。但是,当我运行它时,我只得到一行。我试过每行一个项目,逗号分隔,空格分隔,甚至用大括号包围,用逗号分隔。没有任何作用。
How do I get that chooser dialog to show all my options? Also, is there a way to restrict the selection to one item?
如何让选择器对话框显示我的所有选项?另外,有没有办法将选择限制为一个项目?
Thanks!
谢谢!
回答by Hymanjr300
Here is the solution to select only one linein a list.
这是在列表中仅选择一行的解决方案。
Remove ("Get Specified Text" and "Choose from List") actions.
删除(“获取指定文本”和“从列表中选择”)操作。
Add the "Run AppleScript script" action. 1- Cut the text in the action. 2- Copy/paste this text in the action.
添加“运行 AppleScript 脚本”操作。1- 剪切动作中的文本。2- 在操作中复制/粘贴此文本。
on run
choose from list {"TXT", "RTF", "RTFD", "HTML"} with prompt "Please make your selection" without multiple selections allowed and empty selection allowed
return the result as string
end run
回答by ElmerCat
The trick is to use an AppleScript variable!
诀窍是使用 AppleScript 变量!
The other suggested answers work, but the simplest and most straightforward way is to use an AppleScript variable to define the list choices.
其他建议的答案有效,但最简单和最直接的方法是使用 AppleScript 变量来定义列表选项。
A text variable can store only one item of plain text, but an AppleScript variable can be structured as an array, which is exactly what you need to define a list.
一个文本变量只能存储一项纯文本,但 AppleScript 变量可以构造为一个数组,这正是定义列表所需要的。
In the VariablesLibrary, under Utilities, drag an AppleScriptvariable into the Workflow above the Choose from List action.
Edit the Variable Options and define its Script as an array of text strings, containing your desired list of choices.
在变量库中的Utilities下,将AppleScript变量拖到 “从列表中选择”操作上方的工作流中。
编辑变量选项并将其脚本定义为文本字符串数组,其中包含所需的选项列表。
回答by user3052104
Remove the "Get Specified Text" action.
Add the "Run AppleScript" action above the "Choose from List" action.
In the "Run AppleScript" action, cut the text and copy/paste this text.
on run {} set theList to {"TXT", "RTF", "RTFD", "HTML"} return theList end
删除“获取指定文本”操作。
在“从列表中选择”操作上方添加“运行 AppleScript”操作。
在“运行 AppleScript”操作中,剪切文本并复制/粘贴此文本。
on run {} set theList to {"TXT", "RTF", "RTFD", "HTML"} return theList end
回答by user3052104
You need to break up the text into a list of items, which is what Choose from Listexpects as input. You can use a Filter Paragraphsaction to break up the text, for example return paragraphs that are not empty.
您需要将文本分解为一个项目列表,这就是从列表中选择期望作为输入的内容。您可以使用过滤段落操作来拆分文本,例如返回非空段落。
You don't mention what OS you are running, but Lion added the ability to use Rich Text in the text actions - unfortunately, most of the actions don't work as intended if they actually get Rich Text. In Lion, you can take advantage of some of the (hidden) input item coercions by using something like a Run Shell Scriptaction (you don't need to put anything extra in there, just use the default, which passes items through) to convert Rich Text from the Get Specified Textaction.
您没有提到您正在运行的操作系统,但 Lion 增加了在文本操作中使用富文本的能力——不幸的是,如果它们实际获得富文本,大多数操作都不会按预期工作。在 Lion 中,您可以通过使用类似Run Shell Script操作(您不需要在其中放置任何额外内容,只需使用传递项目的默认值)之类的东西来利用一些(隐藏的)输入项目强制转换从获取指定文本操作转换富文本。
The Choose from Listaction has the Allor Nonebuttons, but there isn't a way to select a specified set of items. It is reasonably easy to write Automator actions, so rolling your own textutil wrapper would be another option.
在从列表中选择行动有全部或无按钮,但没有一种方法来选择一组指定的项目。编写 Automator 操作相当容易,因此滚动您自己的 textutil 包装器将是另一种选择。
回答by Philippe Dube
There are also two Automator Actions that will also solve this problem.
还有两个 Automator Actions 也可以解决这个问题。
One is Split Textwhich allow you to choose a certain delimiter to split the text.
一种是拆分文本,它允许您选择某个分隔符来拆分文本。
The other is Get Words of Textwhich allows you to just get the individual words of text passed as input.
另一个是获取文本词,它允许您只获取作为输入传递的文本的单个词。
If you don't have these actions, you can get them from here:
如果您没有这些操作,可以从这里获取它们:
https://itunes.apple.com/us/app/text-automator-actions-pack/id448838274?mt=12
https://itunes.apple.com/us/app/text-automator-actions-pack/id448838274?mt=12