Applescript 错误无法生成 unicode 文本

发布于 2024-11-04 20:41:54 字数 1639 浏览 2 评论 0原文

我正在尝试编写一个简单的 applescript 脚本来获取 WriteRoom (一个简单的文本编辑器)的内容并通过 markdown 解析器运行它,然后将生成的 html 复制到剪贴板:

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.

所选文本似乎没有复制到剪贴板,而是转换了剪贴板上的任何内容。有什么想法吗?

I'm trying to write a simple applescript script to get the contents of WriteRoom (a simple text editor) and run it through a markdown parser then copy the resulting html to the clipboard:

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")

but when I run it I get an error sometimes:

 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.

The selected text doesn't seem to be copied to the clipboard, instead whatever I had on my clipboard is converted. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素罗衫 2024-11-11 20:41:54

您的应用程序中的文本似乎被复制为 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 定义。

It seems that text from your application is copied as a RTF stream. To convert it to a simple text please try using as text:

(the clipboard as text)

Update

After reading your question again, I I've downloaded WriteRoom and came up with this solution:

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

Then you can use the content variable for further processing. Use the Mac program Accessibility Inspector to find out the UI definition of any window as I did.

自由如风 2024-11-11 20:41:54

这是一个老问题,我看到你已经解决了。
但是看到我用Applescript(不使用WriteRoom,使用Sigil)得到相同的“发生了-25130类型的错误。编号-25130”,我在这些情况下找到了另一个修复方法。

通常,使用 GUI 脚本添加一个小的延迟确实非常重要。实际上,即使有一些预先选择的文本并且只有一个击键,我也得到了这个错误。如果在击键之前和之后延迟0.1,则情况并非如此(或者您必须使用不同的延迟0.2等)。

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

It's an old question and I see you got the fix.
But seeing that I get the same "An error of type -25130 has occurred. Number -25130" with an Applescript (not using WriteRoom, using Sigil) I find out another fix in these cases.

Often it's really very important to add a small delay using GUI scripting. And actually even with some pre-selected text and just having a single keystroke I got that error. Not so if delay 0.1 before and after keystroke (or you have to play with different delay 0.2 and so on).

delay 0.1
tell application "System Events" to keystroke "c" using command down
delay 0.1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文