将 MacTypes::FileURL 从 appscript-ruby 重写为 MacRuby ScriptingBridge
我有一个脚本,可以自动将给定的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该有效:
文件路径声明可能是您问题的原因,但我不确定!
this should work:
the file path declaration could be the reason of your problem, but I’m not sure!