Automator: How do I use the Choose from List action?

六眼飞鱼酱① 提交于 2019-12-05 04:58:15

Here is the solution to select only one line in 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.

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

The trick is to use an AppleScript variable!

The other suggested answers work, but the simplest and most straightforward way is to use an AppleScript variable to define the list choices.

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.

  1. In the Variables Library, under Utilities, drag an AppleScript variable into the Workflow above the Choose from List action.

  2. Edit the Variable Options and define its Script as an array of text strings, containing your desired list of choices.

1) Remove the "Get Specified Text" action.

2) Add the "Run AppleScript" action above the "Choose from List" action.

3) 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

You need to break up the text into a list of items, which is what Choose from List expects as input. You can use a Filter Paragraphs action 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 Script action (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 Text action.

The Choose from List action has the All or None buttons, 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.

There are also two Automator Actions that will also solve this problem.

One is Split Text which allow you to choose a certain delimiter to split the text.

The other is Get Words of Text which 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!