【问题标题】:How can I use an applescript list (copied to the clipboard) in a bash array?如何在 bash 数组中使用 applescript 列表(复制到剪贴板)?
【发布时间】:2022-01-26 18:19:25
【问题描述】:

在 applescript 中,我使用以下代码将剪贴板设置为列表(数组):set the clipboard to {"4", "4", "5"}

是否可以将剪贴板中的列表项分配给 bash 数组?在 applescript 中,将列表项(从剪贴板)分配给变量的代码如下所示:set theList to list of (the clipboard)。这段代码的 bash 等效项是什么?

谢谢!

【问题讨论】:

  • 在 bash 中访问剪贴板是通过 pbcopy 完成的,它读取标准输入和 pbpaste,它写入标准输出。不过我知道的不多。
  • 谢谢,@gurkensaas!我已经停止尝试将 AS (AppleScript) 列表(数组)传输到 Bash。我相信唯一可用的选择是将剪贴板中的 AS 列表的元素作为字符串存储。像这样:set the clipboard to items of theList as string(项目必须在末尾包含一个换行符,以便将它们粘贴到 Bash 中的单独行上)。在 Bash 中,我使用以下代码:clipboard="$(pbpaste)" 将剪贴板的内容放入 var 中。如何从“剪贴板”变量中制作数组:stackoverflow.com/questions/10586153/…
  • 看起来不错,如果您能做到,请考虑发布您自己问题的答案。

标签: arrays bash list applescript clipboard


【解决方案1】:

我对我的问题的回答如下。没有与 set theList to list of (the clipboard) 等效的 Bash。但是,有这段代码将剪贴板的内容放入一个名为“剪贴板”的变量中(前提是剪贴板包含用空格分隔或在单独的行上的项目)。

#!/bin/bash

clipboard="$(pbpaste)" # get the content of the clipboard
theList=( $clipboard ) # make an array from the clipboard content

echo ${theList[1]} # proof that "theList" is an array

【讨论】:

    猜你喜欢
    • 2014-01-02
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多