2011-05-03 76 views
2

我想寫一個簡單的applescript腳本來獲取WriteRoom(一個簡單的文本編輯器)的內容,並通過降價解析器運行它,然後將生成的html複製到剪貼板:Applescript錯誤不能使Unicode文本

tell application "WriteRoom" to activate 
tell application "System Events" to keystroke "a" using command down 
tell application "System Events" to keystroke "c" using command down 
set the clipboard to (do shell script "cd ~;echo \"" & (the clipboard) & "\" >> writeroom.md; /usr/local/bin/markdown writeroom.md") 

但是當我運行它,我得到一個錯誤有時

Can’t make {«class RTF »:«data RTF 7B5C727466315C616E73695C616E7369637067313235325C636F636F61727466313033385C636F636F617375627274663335300A7B5C666F6E7474626C5C66305C6673776973735C6663686172736574302048656C7665746963613B7D0A7B5C636F6C6F7274626C3B5C7265643235355C677265656E3235355C626C75653235353B7D0A5C706172645C74783536305C7478313132305C7478313638305C7478323234305C7478323830305C7478333336305C7478333932305C7478343438305C7478353034305C7478353630305C7478363136305C7478363732305C716C5C716E61747572616C5C7061726469726E61747572616C0A0A5C66305C66733332205C636630202A20746573745C0A2A20617364665C0A2A206E6F5C0A2A207465737474657374746573747D», «class utf8»:"* test 
* asdf 
* no 
* testtesttest", «class ut16»:"* test 
* asdf 
* no 
* testtesttest", uniform styles:«data ustl0200000090000000000000001400000020000000010000002100000000000000010000006C000000040000000000000000000000020100000100000000000000050100002C000000646D616E2400000001000000040000000100000000000000000000000900000048656C76657469636100000006010000040000000000100007010000060000000000000000000000»} into type Unicode text. 

選定的文本似乎並沒有被複制到剪貼板,而不是無論我對我的剪貼板轉換。有任何想法嗎?

+0

您有時必須在複製和獲取剪貼板之間添加一個短(<0.1s)的延遲。 – user495470 2011-05-04 01:46:01

回答

2

這似乎從你的應用程序,文本複製爲RTF流。將其轉換爲一個簡單的文本,請嘗試使用as text

(the clipboard as text) 

更新

再次閱讀您的問題後,我我已經下載WriteRoom並用此溶液想出了:

tell application "WriteRoom" to activate 
tell application "System Events" 
    tell application process "WriteRoom" 
     set content to (value of text area 1 of scroll area 1 of front window) as text 
    end tell 
end tell 

display dialog content 

然後你可以使用content變量進行進一步的處理。使用Mac程序輔助功能檢查器可以像我一樣找出任何窗口的UI定義。

+0

噢命令變量是舊代碼,刪除:) – errorhandler 2011-05-03 04:51:40

+0

我試過使用'(剪貼板作爲文本)',但它仍然無法工作*所有的時間*,有時我得到一個錯誤:「錯誤」一個錯誤的類型-25130發生了。「number -25130」 – errorhandler 2011-05-03 04:57:41

+0

你可以嘗試進行測試以將剪貼板設置爲靜態文本,以查看它是否會生效?如果是這樣,你將不得不另闢蹊徑如何轉換RTF。請張貼您的測試結果。例如:'告訴應用程序「Finder」將剪貼板設置爲「某些剪貼板文本」' – 2011-05-03 04:59:31

1

這是一個老問題,我看你得到了修復。 但看到的是我得到同樣的「-25130類型的錯誤已經發生。數-25130」有一個AppleScript(不使用WriteRoom,使用印記),我發現在這些情況下,另一種修復。

通常它真的很重要使用GUI腳本添加一個小delay。實際上,即使有一些預先選定的文本,只有一個keystroke我得到了這個錯誤。事實並非如此,如果delay 0.1之前和之後keystroke(或者你有不同的延遲0.2等打)。

delay 0.1 
tell application "System Events" to keystroke "c" using command down 
delay 0.1