如何保存 OS X 仪表板小部件生成的文件?
我有一个 Web 应用程序,正在将其移植到 OS X 仪表板小部件。 Web 应用程序使用 JavaScript 在客户端生成一些数据,然后,当用户想要保存数据时,将其发送到服务器端脚本,该脚本使用 Content-disposition:attachment;
Content-disposition:attachment; HTTP 标头,在大多数浏览器中触发保存文件对话框。
我尝试在仪表板环境中复制此内容。小部件就这样消失了。我不知道,但我怀疑它可能实际上正在导航到不熟悉的内容。
那么,如何触发“保存文件对话框”——或者,如果失败,请使用任何方法将 Widget 生成的数据保存为文件?
I've got a web app that I'm porting to an OS X Dashboard widget. The web app generates some data on the client side using JavaScript, and then, when the user wants to save it, sends it to a server-side script which relays the data back with the Content-disposition: attachment;
HTTP header, triggering a save-file dialog in most browsers.
I've tried duplicating this in the Dashboard environment. The Widget simply disappears. I don't know, but I suspect that it may be actually navigating to the unfamiliar content.
So, how do I trigger a "save file dialog" -- or, failing that, use any method at all to save the data the Widget generates as a file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,不可能通过“保存文件”对话框从仪表板小部件保存文件,因为小部件的目的是显示信息(有或没有互联网访问)、进行计算或控制应用程序。
但是,您可以选择三种方式在本地存储数据:
将数据存储在小部件的首选项中。
通过 setPreferenceForKey 小部件方法并使用 preferenceForKey 小部件方法。
仅当数据属于小部件并且不必在小部件外部访问时,这才是一个选项。另外,数据大小不应该太大。
通过 小部件的系统命令。
此处可以使用任何脚本语言(sh、perl、ruby、python、AppleScript...)。
编写一个基于Cocoa/Objective-C的小部件插件。
As far as I know it is not possible to save a file from a dashboard widget through a "save file" dialog because the intent of widgets is to display information (with or without internet access), to do calculations or to control applications.
However you have three options to store data locally:
Store the data in the preferences of the widget.
Set the data through the setPreferenceForKey widget method and retrieve it with the preferenceForKey widget method.
This is only an option if the data belongs to the widget and does not have to be accessible outside the widget. Also the data size should not be too big.
Execute scripts through the system command of the widget.
Any scripting language can be used here (sh, perl, ruby, python, AppleScript, ...).
Write a Cocoa/Objective-C based widget plugin.
正确的方法是使用可可小部件插件,它可以让您使用另存为对话框。快速的方法是这样的:
这告诉 bash 将 stdin 传输到桌面上的文件,然后写入 stdin。
The right way to do it is a cocoa widget plugin that will let you use a save as dialog. The quick way to do it is something like this:
This tells bash to cat stdin to a file on the desktop, then writes to stdin.