1

交易是这样的:

我使用http://www.clipmenu.com/ ClipMenu 有 20 种状态的剪贴板,因为我需要复制一些分隔的 txt 文件的每一行。所以我打开 txt 文件,然后遍历每一行点击command+ shift+→</kbd> then command+c then ↑</kbd> and so on until i reach the top and i have all the lines copied and stored in the history of ClipMenu.

我的问题是,有没有办法制作一个以自动方式复制每一行的服务或脚本?我想我可以制作一个重复这些击键的脚本,直到它到达 txt 文件的顶部,但我不知道如何做到这一点。

非常感谢。

4

3 回答 3

0

ClipMenu 似乎忽略了“瞬态”剪贴板,因此您还需要在复制操作之间进行延迟:

read POSIX file "/Users/username/Documents/test.txt" as «class utf8»
repeat with p in reverse of paragraphs of result
    if contents of p is not "" then set the clipboard to contents of p
    delay 1
end repeat

或使用 UI 脚本:

delay 1
tell application "TextEdit"
    activate
    set n to number of paragraphs of document 1
end tell
tell application "System Events"
    key code {125, 123} using command down
    repeat n times
        key code 124 using {shift down, command down}
        keystroke "c" using command down
        key code 126
        delay 1
    end repeat
end tell

关键代码列在 Events.h 中。

于 2013-04-13T11:04:10.607 回答
0

我不知道如何使用 Automator 来做到这一点,但使用单声道 [MonoMac] 非常简单:

using (System.IO.FileStream file = new System.IO.FileStream("path", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)) {
    using (System.IO.StreamReader reader = new System.IO.StreamReader(file)) {
        while (!reader.EndOfStream) {
            String line = reader.ReadLine ();
            System.Windows.Forms.Clipboard.SetText(line);
        }
    }
}
于 2013-04-12T15:27:48.723 回答
0

尝试:

set fileText to read (choose file) as «class utf8»

set filePara to paragraphs of fileText
repeat with aPara in filePara
    set aPara to contents of aPara
    if aPara ≠ "" then set the clipboard to aPara
    end repeat
于 2013-04-12T16:05:27.290 回答