2013-04-12 30 views
1

這筆交易的每一行是這樣的:複製文本的OSX上

我用http://www.clipmenu.com/ ClipMenu有剪貼板的20個州,因爲我需要複製分離一些txt文件的每一行。所以,我打開txt文件,我經過每行打命令 + 轉變 + 然後命令 + Ç然後依此類推,直到我到達頂部,我把所有的將行復制並存儲在ClipMenu的歷史記錄中。

我的問題是,有沒有一種方法,使服務或腳本,以自動化的方式每一行副本?我想我可以作出這樣的重複這些按鍵,直到它到達txt文件的頂部的腳本,但我不知道如何使它如此。

非常感謝。

回答

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); 
     } 
    } 
} 
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 
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。

+0

然後第二個工作,但行的每個文本文件的數量而變化。我可以設置重複重複,直到它到達第一行嗎?謝謝。 – dusanvf

+0

我編輯了答案。第一個腳本也適用於我,但是您是否正確指定路徑? – user495470

+0

現在它可以工作,但它不會複製第一行。我該如何解決這個問題?謝謝。 – dusanvf

相關問題