使用 applescript 处理 automator 中选定文本的列表
在尝试执行从选定文本作为输入打开多个选项卡的自动操作时,我遇到了一个暂时无法解决的 applescript 问题。这包括答案,我将其发布在这里是因为我无法找到有关如何处理“输入”中的数据以接收“任何应用程序”自动操作中选定的“文本”的文档,所有内容都是针对以下文件的已经作为一个列表出现了。
当放入 applescript 操作时,您会得到:
on run {input, parameters}
这里的问题是输入不是列表格式,并且尝试对其执行任何操作都会破坏脚本或引发错误。即我不能这样做:
repeat with URL in input
set this_URL to URL
那么我如何将选定文本的列表视为项目列表?
While trying to make an automator action that opens multiple tabs from selected text as input I ran into an applescript issue I wasn't able to solve for awhile. This includes the answer and I'm posting this here because I just wasn't able to find documentation on how to handle data in "input" for a receives selected "text" in "any application" automator action, everything is for files which comes in as a list already.
When putting an applescript action in, you get:
on run {input, parameters}
the problem here is that input isn't in a list format and trying to do anything with it breaks the script or throws an error. ie I can't do:
repeat with URL in input
set this_URL to URL
So how can I treat a list of selected text as a list of items?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决方案是首先将输入视为字符串,然后分解每个段落。
如果在执行“每个段落”之前不先将输入“视为字符串”,它将无法工作。
这是最终的工作脚本,将“some_url”替换为您自己的。您将能够在编辑器中选择多行文本,并将每一行视为固定网址的参数,在新的 Safari 选项卡中打开每一行。这可以通过为 url 上的多个参数分隔每一行来扩展。
举个例子,假设您拥有该列表并使用“http://stackoverflow.com/posts/”和“http://stackoverflow.com/posts/”获得了上述服务。 this_URL
您现在可以选择它们,单击服务并选择您的“StackOverflow - 查看问题”服务,它将在新的 safari 选项卡中附加并打开每个服务。就我而言,我需要验证服务器中的多个 dns 条目是否仍然有效,并进行大量 whois 查找。
the solution is first treat input as a string then break apart every paragraph.
Without treating input "as string" first before doing "every paragraph of" it won't work.
Here's the end working script, replace the "some_url" with your own. You'll be able to select several lines of text in an editor and treat each one as a parameter to your fixed url opening each in a new safari tab. This could be expanded upon by having each line be delimited for multiple params on the url.
As an example say you had the list and had a service of the above using "http://stackoverflow.com/posts/" & this_URL
you could now select them click services and choose your "StackOverflow - view questions" service and it'll append and open each one in a new safari tab. In my case I needed to verify multiple dns entries in our server as still valid and do a bunch of whois lookups.
我一直在寻找同样的东西,只是寻找从 Automator 到 AppleScript 输入的文件。
ddowns 的技巧对此不起作用,但最终使用了这个,希望它对寻求解决我遇到的相同问题的人有帮助:
I was looking for the same thing, just for files as input from Automator to AppleScript.
ddowns's trick didn't work for that, but ended up using this, hope it's helpful for someone looking for solving the same issue I ran into:
正如 Hanzaplastique 所说,对于 Automator 中的 AppleScript,您不需要 Safari AppleScript,因为有一个 Action。我使用以下操作:
我将其用作添加到“服务”菜单中的工作流程,以便我可以右键单击电子邮件中的选定文本,然后在 Safari 选项卡中打开多个 URL。
特别是,我通过电子邮件收到服务器/WordPress 更新,但 URL 只是域的顶层,我想跳转到 WordPress 的插件页面。所以,我的 AppleScript(感谢 Hanzaplastique)是:
我发现我需要“返回 selectedFiles”。总是神秘的(对我来说)文本分隔符可能不是必需的,并且来自仅提取单个 URL 的先前版本。
As Hanzaplastique says, for AppleScript within Automator, you don't need the Safari AppleScript because there's an Action for that. I use the following Actions:
I use it as a Workflow added to the Services menu so that I can right-click on selected text in an email and open multiple URLs in Safari tabs.
In particular, I get Server / WordPress updates in an email but the URLs are just the top level of the domains and I want to jump to the plugins page of WordPress. So, my AppleScript (with thanks to Hanzaplastique) is:
I found I needed the 'return selectedFiles'. The always mysterious (to me) text delimiters may not be necessary and come from the previous version which only pulled out a single URL.