Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Development

Problem with copying to clipboard under Leopard

Author Message
codemaster07



Joined: 03 Nov 2007
Posts: 1
Location: Germany

Posted: Sat Nov 03, 2007 - 1:34 pm    Post subject: Problem with copying to clipboard under Leopard Reply with quote

Hello @ll!

I have a strange problem with my widget. On a click event of a link, a javascript function executes

Code:
var mytext = "Hello!";
widget.system("/bin/echo -n \'" + mytext + "\' | /usr/bin/pbcopy", null);


I developed the widget with dashcode and it works fine with the simulator. But when i install the widget to the dashboard, i get the following message in the log and the clipboard leaves empty:


Quote:
DashboardClient[13896]: (de.megolan.widget.zitatenet) file:///Users/mmeyer/Library/Widgets/zitatenet.wdgt/zitatenet.js: Value undefined (result of expression widget.system) is not object. (line: 185)


Line 185 is the code above. In my info.plist i allowed the widget to use the command line:

Quote:
<key>AllowSystem</key>
<true/>


So what´s wrong in my code? Please help! Thank you!
View user's profile Send private message Send e-mail Visit poster's website Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Sun Nov 04, 2007 - 11:40 am    Post subject: Reply with quote

Did you try out, if any other system-command works? Only executing the first command (echo) for example? Or doing everything in two system-calls, if possible?

Plus, you're using widget.system synchronously which isn't recommended by Apple, afaik. If you use the command asynchronously, you might be able to look for the widget.system properties "outputString", "errorString" or "status". Maybe one of them gives a clue on what's going wrong.

PS: Here's the Apple-Doc, just in case you didn't know:

http://developer.apple.com/documentation/AppleApplications/Reference/Dashboard_Ref/GadgetObj/chapter_2_section_3.html#//apple_ref/doc/uid/TP40001339-CH203-DontLinkElementID_24
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
gandreas



Joined: 16 Jun 2005
Posts: 114

Posted: Mon Nov 05, 2007 - 12:10 pm    Post subject: Reply with quote

There are several major problems with your approach:

1) You should never use synchronous widget.system calls in production code - they are for debugging purposes only. (One major reason they are bad is that they can completely block the Widget, and with one of the performance strategies in Tiger to run multiple Widgets in the same process, this means that you end up blocking multiple Widgets, not just your own) I wouldn't be surprised if at some point they stop working all together (and only function inside Dashcode)

2) Using system with arbitrary text coming from somewhere else is a major security risk - imaging this:

Code:

mytext = "\' && /bin/rm -rf \'/";
 

This will result in your widget.system trying to delete everything on all the hard drives

3) There are DOM events for manipulating the clipboard (such as "onCopy") which may be sufficient for your needs

4) If those aren't sufficient, file an enhancement bug with Apple to cleanly expose clipboard APIs in Dashcode, and in the meantime write a native code plugin to manipulate the clipboard.
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group