...A little utility that translates the contents of an item dropped on its window into structured text suitable for processing by Ruby or Python. Years ago I wrote ‘xicon’ to process dropped files with shell (or other) scripts, but—because it depends on the Tracker—it cannot respond to other kinds of dropped items, such as NetPositive links. Using Ycon is rather less straightforward, and really needs a scripting language more capable than the shell, but—with suitable scripting—it is capable of handling almost anything dropped on its window.
(The name ‘Ycon’ is pretty much a random choice and is not really derived from anything, though I guess it has a family relationship to ‘xicon’. Also, because I wanted it for a Ruby script that processes Youtube links…)
The information is received by Ycon’s window in the form of a BMessage (whose exact form depends on the item), and is converted into a text string that can be directly translated by Ruby or Python into a a corresponding list structure (“Array” in Ruby). Both Ruby and Python represent lists in essentially the same way—as comma separated items enclosed between square brackets— so this is how the strings generated by Ycon appear. Passing the entire string to an ‘eval’ method in either language will generate the appropriate list/array object.
Distributed in this package are the Ycon executable and a short Ruby library script that shows how to use Ycon and provides some basic utility. Also supplied is the ‘RubyTube’ script I use to play YouTube videos. This is not in any way to step on Cyan’s toes—his ‘TubePositive’ will be more convenient for most people— but if you do have Ruby 1.8.4 installed, RubyTube might work for you too.
Apologies for not including any Python examples, but I’ve done no more at thia point than check that it works with that language. Shouldn’t be too hard to figure out!
Ycon -- the executable itself. For easy access, you should move it
to /boot/home/config/bin, or somewhere else on your path.
bedrop.rb -- a little Ruby script containing the "BeDrop" class, to
provide a convenient interface to Ycon and demonstrate its usage.
It has an 'each' method that will return arrays representing the
dropped items, and an 'each_url' that specifically extracts the
URL(s) in the dropped item (if any). if you want to use this, you
should place it in /boot/home/lib/ruby/site-ruby or somewhere else
accessible by the interpreter.
README.html -- this file.
SRC -- directory containing the program source.
RubyTube -- a Ruby script (of 'xicon' type so it can be invoked with a click)
that extracts the video URL from a YouTube link dropped on its Ycon
window, and invokes 'vlc' to play it. Of course requires both Ruby
and vlc to be available -- and xicon if you want to click-start it.
(Unlike TubePositive, it decodes the YouTube page itself, without
going to any other site, but correspondingly it only handles YouTube
-- no other video sites. It is able, however, to play a saved Bookmark
as well as a dragged link.)
To see the sort of output Ycon generates, the easiest way is to fire it up in a Terminal window, drop some items on the (floating) window that it opens, and look at what gets printed. (The command is just ‘Ycon’; there are no command-line arguments in this version. Sorry about the capitalization (:-/) but it will usually be invoked from a script anyway; change it if you like.)
Each dropped item is converted into a list-form text string, delimited by square brackets, with comma-separated items. Most of the items will themselves be lists (again bracket-delimited). To make it readable, the output is split into multiple lines—each sub-list beginning on a new line and indented by spaces. The final bracket of the message appears non-indented on a line by itself.
The very first item in the top-level list is the ‘what’ member of the dropped message (as a 4-character string). Following items are all lists representing the fields in the message; each has three or more members. The first member is the name of the message field, the second is its (BeOS) data type, and the remaining ones represent the actual data. There will be one item (of appropriate form) for each item of that name and type in the message. Ycon doesn’t attempt to handle binary data (which would be hard to pass as text) but passes or translates most others appropriately. Any data it can’t handle is represented as “[‘n bytes’]” where ‘n’ is the actual size of the field.
To get the data into a Ruby (if you don’t use bedrop.rb) or Python script, you should create a pipe object with the ‘popen’ method (of the IO class in Ruby), and read the data from that. From that point it’s up to you.
Note that converting the text generated by Ycon using an ‘eval’ call works fine for most dropped items, which won’t contain weird strings. However, Ycon also tries to retrieve clipboard items, and these can contain characters that will confuse ‘eval’. If you need to be completely general, you will have to check the received data for suitability before invoking ‘eval’ on it.
Ycon is copyrighted free software by Pete Goodeve and is released under the same license as Ruby. See the Ruby license at: http://www.ruby-lang.org/en/LICENSE.txt
Ycon may be freely copied in its entirety providing this notice, all source code, all documentation, and all other files are included.
Ycon is Copyright© 2008 by Pete Goodeve