...A little utility that translates the contents of any item dropped on its window into structured text suitable for processing by Ruby or Python. It also handles clipboard items pasted into its window. 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. With suitable scripting, Ycon is capable of handling almost anything dropped on its window, though—unlike a Xicon script—it has to be running before you can drop items on it. Its output probably requires a more capable scripting language than the shell to be useful. This is the second release: it mostly adds some command-line options.
(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 originally wanted it for a Ruby script to process 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 (with precautions possibly needed in Python—and in Ruby as well if the strings are not well-formed).
Distributed in this package are the Ycon executable and short Ruby and Python scripts that show how to use Ycon. A more detailed Ruby script provides some extended basic utility. (A ‘RubyTube’ script—that played YouTube videos through vlc without needing a “ripper” site—was included in the first release but stopped working soon after, as YouTube changed its scheme, so is no longer included here.
- Ycon
- —the executable itself. For easy access, you should move it to /boot/home/config/bin, or somewhere else on your path.
- testycon.rb
- —a basic Ruby script that shows how to use Ycon, and will print out the contents of each dropped object.
- testycon.py
- —a basic Python script that shows how to use Ycon, and will print out the contents of each dropped object.
- bedrop.rb
- —a little Ruby script containing the “BeDrop” class, to provide a convenient interface to Ycon.. It has an ‘each’ method that will return arrays representing the dropped items, and an ‘each_url’ that specifically extracts the URL in the dropped item (if any). if you want to use this, you should place it in /boot/home/config/lib/ruby/site_ruby (/boot/common/lib/ruby/site_ruby in Haiku) or somewhere else accessible by the interpreter.
- README.html
- —this file.
- SRC
- —directory containing the program source.
To see the sort of output Ycon generates, the easiest way is to fire it up from a Terminal window, drop or paste some items into the window that it opens, and look at what gets printed. Note that the output will usually be very different for copy/pasted data than for dragged items. The message from a drop has a standard format which just refers to any large data and is usually fairly short; a clipboard item usually has a lot of data and can be any length. (The basic command is just ‘Ycon’. Optional arguments are detailed below. 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. Many 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 (this is normally used by the script to decide when the output is complete).
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 by default doesn’t attempt to pass on binary data in full, but translates most other types appropriately. Any data it doesn’t handle is represented as ”’n bytes’ ” where ‘n’ is the actual size of the field. A command-line option will direct it to pass on binary data as well (as an octal-character string).
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, ‘os’ in Python), and read the data from that. From that point it’s up to you, but see the ‘testycon…’ scripts for inspiration.
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 will also retrieve pasted 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, or as bedrop.rb now does, handle any exception that gets generated.
- -d
- —Output the data in all message items in full, even if they aren’t one of the known item types, as an octal-character (“\nnn“) string. If this switch is not used, unknown data is shown as ”’n bytes’”.
- -f
- —Provide a floating window in all Workspaces. The original Ycon did this by default, but that proved to be rather a nuisance, so by default it now opens a normal window in the current Workspace. If you want the old behaviour, use this switch. [Note, though, that the Deskbar won’t list a floating window.]
- -t string
- —Set the title of the window to string.
- -x n
- —Set the X-coordinate of the left edge of the window to n If not specified, the default is 20 pixels from the left.
- -y n
- —Set the Y-coordinate of the top edge (ignoring the tab) of the window to n. If not specified, the default is 20 pixels from the top.
Ycon knows about the following item types, and formats them suitably. The data in all others is seen only as a string of bytes.
- CSTR
- —A standard character string. Output as a quoted string.
- MIME
- —A MIME type. Output as a quoted string.
- LONG
- —A long integer. Output as decimal.
- PNTR
- —A pointer value. Output as hexadecimal.
- BPNT
- —A BPoint. Output as an array of two floats.
- RREF
- —An entry_ref. Output as a two-string-element array. The first string is the name in the ref, the second is its full path.
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-2012 by Pete Goodeve