将 MacTypes::FileURL 从 appscript-ruby 重写为 MacRuby ScriptingBridge

发布于 2025-01-04 19:58:46 字数 894 浏览 3 评论 0原文

我有一个脚本,可以自动将给定的 PDF 附加到 BibDesk 中的出版物。使用 appscript-rb,以下代码片段可以完美运行:

BibDesk = Appscript.app('BibDesk')
selection = BibDesk.document.selection.get[0]
f = MacTypes::FileURL.path(curfile)
selection[0].linked_files.add(f,{:to =>Selection[0]})
selection[0].auto_file

尝试为 MacRuby 重写它,我想出了以下结果:

framework 'Cocoa'
framework 'ScriptingBridge'

file=NSURL.fileURLWithPath("file:///Users/Stian/Downloads/Telearn.pdf")
dt=SBApplication.applicationWithBundleIdentifier("edu.ucsd.cs.mmccrack.bibdesk")
d= dt.documents[0].selection[0]
d.linkedFiles.add(file,[:to=>dt.documents[0].selection[0]])

但是,这会导致 MacRuby 崩溃(我认为这也是因为它是错误的)。我刚刚得到:

 84829 abort      macruby attach_bibdesk.rb

如何将 appscript-ruby 重写为正确的 MacRuby ScriptingBridge 格式?

I have a script that automatically attaches a given PDF to a publication in BibDesk. Using appscript-rb, the following snippet works perfectly:

BibDesk = Appscript.app('BibDesk')
selection = BibDesk.document.selection.get[0]
f = MacTypes::FileURL.path(curfile)
selection[0].linked_files.add(f,{:to =>Selection[0]})
selection[0].auto_file

Trying to rewrite it for MacRuby, I came up with the following:

framework 'Cocoa'
framework 'ScriptingBridge'

file=NSURL.fileURLWithPath("file:///Users/Stian/Downloads/Telearn.pdf")
dt=SBApplication.applicationWithBundleIdentifier("edu.ucsd.cs.mmccrack.bibdesk")
d= dt.documents[0].selection[0]
d.linkedFiles.add(file,[:to=>dt.documents[0].selection[0]])

However, this crashes MacRuby (which I am assuming is also because it is wrong). I just get:

 84829 abort      macruby attach_bibdesk.rb

How can I rewrite the appscript-ruby into proper MacRuby ScriptingBridge format?

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

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

发布评论

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

评论(1

鸢与 2025-01-11 19:58:46

这应该有效:

 framework 'Cocoa'
 framework 'ScriptingBridge'

 file_path = NSURL.fileURLWithPath("/Users/Stian/Downloads/Telearn.pdf")
 bib_desk = SBApplication.applicationWithBundleIdentifier("edu.ucsd.cs.mmccrack.bibdesk")
 selected_doc = bib_desk.documents.first.selection.first
 bib_desk.add(file_path, to:selected_doc)

文件路径声明可能是您问题的原因,但我不确定!

this should work:

 framework 'Cocoa'
 framework 'ScriptingBridge'

 file_path = NSURL.fileURLWithPath("/Users/Stian/Downloads/Telearn.pdf")
 bib_desk = SBApplication.applicationWithBundleIdentifier("edu.ucsd.cs.mmccrack.bibdesk")
 selected_doc = bib_desk.documents.first.selection.first
 bib_desk.add(file_path, to:selected_doc)

the file path declaration could be the reason of your problem, but I’m not sure!

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