过滤剪贴板并另存为数据列表

Filter clipboard and save as data list

我正在尝试让 AppleScript 从剪贴板中找到 some 关键字并将它们列在新的剪贴板中

例如:我将这一行复制到剪贴板中 "order KAFGEFEF price 999 date 17 order KADFSDGS price 874 date 18"`

结果将是

K1AFGE2FEF
K1ADFSD2GS

甚至更好

K1AFGE2FEF : 999
K1ADFSD2GS : 17

我要收集的数据总是以"K1...."开头,有10个字符。

我实际上有一个旧的 Javascript 可以解决问题,但我需要改用 AppleScript。

我真的不知道从哪里开始,也许我应该从 pbcopy 和 egrep 开始?

希望这是有道理的。

亲切的问候。

从你的问题中不清楚你的剪贴板数据是如何构建的或者你想要的输出是什么。对于初学者,这里有一个 Applescript 解决方案,可以从剪贴板中提取订单、价格和日期值。它假定订单、价格和日期始终按特定顺序组合在一起,并且剪贴板上的一行文本中可以有多个订单-价格-日期组。例如:

order K1AFGE2FEF price 999 date 17 order K1ADFSD2GS price 874 date 18

然后以下 Applescript 将提取每个订单、价格和日期三元组并将其保存为主列表中的三项子列表:

set masterList to {}
set tid to AppleScript's text item delimiters
try
    set AppleScript's text item delimiters to "order "
    repeat with i in (get (the clipboard)'s text items 2 thru -1)
        tell i's contents
            try
                set currOrder to first word
                set AppleScript's text item delimiters to "price "
                set currPrice to (get its text item 2)'s first word
                set AppleScript's text item delimiters to "date "
                set currDate to (get its text item 2)'s first word
                if (currOrder starts with "K1") and (currOrder's length = 10) then set end of masterList to {currOrder, currPrice, currDate}
            end try
        end tell
    end repeat
end try
set AppleScript's text item delimiters to tid
return masterList -- {{"K1AFGE2FEF", "999", "17"}, {"K1ADFSD2GS", "874", "18"}}

然后可以将主列表进一步处理成您想要的任何输出。