
Scripting the Haiku GUI with hey - adamnemecek
https://www.haiku-os.org/blog/humdinger/2017-11-05_scripting_the_gui_with_hey/
======
TheAceOfHearts
I haven't tried BeOS/HaikuOS or the hey tool, but I've used the equivalent on
macOS. The hey language seems a bit awkward to me, just like AppleScript. A
few years back Apple added JavaScript support for OSA, which was a huge win
for me. It took me a while to learn how to navigate the docs and use the APIs,
but it's proven to be incredibly powerful.

Over time I've built up a small list of utilities for common UI interactions.
Here's an example: Get the list of tabs from the frontmost Safari window [0].
Occasionally I'll be researching some topic with a bunch of tabs open, and I
want to go work on something else. When that happens I just grab all the URLs
in that window and save it in a text file which I re-open later when I want to
continue researching the subject.

IMO, the biggest problem I've encountered with OSA scripts (and presumably it
also applies to this hey tool) the lack of REPL and inspector. On macOS you
can use Safari's dev tools to debug JS OSA scripts, but it's incredibly
brittle. Trying to access certain object properties will just cause it to
crash, or it might print the identifier of the thing which you're accessing
which doesn't add much value.

[0]
[https://gist.github.com/cesarandreu/8d6ccd70bcac81d1a45941ae...](https://gist.github.com/cesarandreu/8d6ccd70bcac81d1a45941ae996a6e32)

~~~
tudelo
I understand not fixing something if it isn't broken, but is there a reason
you don't just use a "Bookmark Open Pages" feature? I'm pretty sure it's
standard in the big browsers, but definitely on chrome.

~~~
TheAceOfHearts
I just checked with Safari and it does indeed provide that functionality, and
I wasn't aware it was an option.

Honestly, I just find it convenient to get a list of URLs, and dealing with
regular text files. Sometimes interfaces are too limiting r slow, and
manipulating the list in a text editor ends up being easier.

Another of my use-cases for this is to regroup tabs when I fork into random
topics. e.g. Sometimes I end up opening a bunch of tabs that are tangentially
related to the subject and I want to move em into a new window or stash em for
later.

It's also convenient to grab a manually opened list of URLs in cases where I
want to perform some one-off scraping task.

------
peterburkimsher
I use AppleScript frequently, and one of the reasons I can't bring myself to
move to Linux is because of the excellent API into every app.

Somehow "hey" just doesn't seem to offer the ecosystem that AppleScript does.
Even though I really don't like the latest versions of macOS and iOS, I still
prefer the old Apple ecosystem to the fragmented platforms of Windows and
Linux (or Haiku).

~~~
adamnemecek
what exactly do you script with it if i may ask?

~~~
peterburkimsher
Mostly text processors. Bash scripting doesn't always handle Unicode nicely.
For Pingtype ( [https://pingtype.github.io](https://pingtype.github.io) ) I
need data in Chinese. I get that from websites. Sometimes I can download it
with curl, other times I need to tell Safari to get the source for me.
Language syntax like "every paragraph" and "set applescript's text item
delimiters to" are much easier to handle than str.split() and IFS.

File reading and writing are easy. Getting and setting track data in iTunes is
easy. Finding selected items in the Finder is easy. I've been using more "do
shell script" recently as my knowledge of command-line tools increases.

It's slower to run than other languages, but when I just want a quick one-off
script to generate some data, it's faster for me to code it in AppleScript
instead of spending hours debugging it in another language.

All my processing for PlinyPedia (
[http://peterburk.github.com/pliny](http://peterburk.github.com/pliny) ) was
in AppleScript - splitting the XML into separate files grouped into folders,
naming those folders, moving the footnotes to the bottom and adding links to
quickly move up and down, and finally generating a basic iUI interface.

I also wrote scripts to transpose chord progressions to Roman Numerals by
looking up the values in a table, select cells diagonally in Excel, and turn
my Facebook friends list into an iTunes database. (The iTunes database is URL
tracks that trigger a PHP script running locally that opens Safari with the
URL - it's basically a bookmarks manager with Smart Playlists. If you can
recommend a better database, please do.)

~~~
petre
Sounds like a good usage case for Perl rather than bash. The former has good
Unicode support and you can use the standard lib + Mojolicious to fetch data
from the web and serve other data to Safari. No need for bash + command line
tools + PHP + web server.

~~~
peterburkimsher
I'm not trying to serve data to Safari (usually), I'm trying to read data from
Safari. I often need to get the source of a webpage that's already loaded
after a login screen, or with some user interaction.

For example, scrolling down to load all my Facebook messages into the left-
hand bar. Or segmenting text into 5000-character blocks, copy-pasting into
Google Translate, and getting the output.

With any command-line tools, it would be a hassle, if it's possible at all.
With AppleScript, it's easy.

~~~
jcelerier
> For example, scrolling down to load all my Facebook messages into the left-
> hand bar.

sounds like an X-Y problem. Why wouldn't you just use the facebook API ?

~~~
peterburkimsher
I don't think there's an API to export all my messages.

------
hnbroseph
the small titlebar seems neat, but the utility seems diminished (i have a
smaller target area via which i can grab a window). does the compactness
somehow play into other features of the windowing system, or is it just style?

~~~
mastax
You can stack windows together: [https://www.haiku-
os.org/files/stack.png](https://www.haiku-os.org/files/stack.png)

------
jlebrech
Haiku could be the perfect netbook laptop OS IMHO. no nonsense but still
modern.

~~~
qubex
Having used BeOS back in its halcyon days of the mid-to-late nineties and a as
somebody that maintains an active Haiku installation (albeit under VMWare) I
have to agree with you.

It is definitely lacking in the browser department (which seems so crucial to
most people) but beyond that, it’s a very dependable and responsive OS with
absolutely modest hardware requirements.

(I also have a working BeBox 603e 133 MHz but I use it very rarely because I’m
very concerned about the health of the IDE HD.)

~~~
jlebrech
all it needs for regular from out of backpack development use is a browser and
docker.

------
vadimberman
I played with BeOS when it was still alive, it was light, nice, and fun, and I
miss these cute icons, but frankly, I simply don't see the point of reviving
it now.

~~~
adamnemecek
There an insane amount of stuff to be learned from failures. From my
understanding, one of the main reasons behind their demise was their business
plan. Version for PCs with <256RAM were free, you paid for 256+MB. However
BeOS ran so efficiently that no one ever needed 256+MB so few people bought
it.

~~~
chipotle_coyote
While it's been ~18 years, this doesn't at all sound correct to me. BeOS was a
commercial product from its very beginning. There were free "developer
release" versions, but it was sold as boxed software from R3 on. The last
official release, BeOS R5, had a free version called "BeOS Personal Edition,"
which ran as an app inside Windows or Linux, but the full version of R5 was
still commercial, at $69.95 (with an upgrade discount). I don't recall any
licensing requirements pinned to the amount of RAM you had.

A large part of what did in BeOS was a combination of Microsoft's OEM
licensing requirements and Be's steadfast belief that the only path to success
was pre-installation on a major PC brand. IIRC, if you offered Windows pre-
installations at all, you had to pay for every machine that Windows _could_ be
installed on whether or not it was actually installed, and you couldn't offer
machines capable of dual-booting. Be concentrated their efforts on BeIA, an
"internet appliance" version of the OS, which was dead in the water --
according to a lawsuit Be filed against Microsoft, MS pressured their OEMs not
to partner with Be on both BeOS and BeIA. (Microsoft settled the suit for
around $24M, IIRC.)

Personally, I think BeOS might have been able to survive as a niche OS if Be
had kept their focus solely on it, kept the price competitive with boxed Linux
distributions (those were a thing back then), and _not_ been dedicated to the
"go big or go home" mantra, but I don't have any inside info to prove (or
disprove) that.

~~~
allenbrunson
I was one of the people who worked at Be, right up to the very end, when the
company went out of business, got absorbed into Palm, and I was laid off. I
remember all this the same way you do.

... Except that I don't think there is anything they could have done that
would have made them successful, at that point in time, other than possibly
not playing hardball when Apple came calling. Microsoft's stranglehold on the
industry was just too great.

~~~
qubex
I just wanted to let you know that to this very day I mourn the loss of Be Inc
and BeOS. Whatever work you did there I’d like you to know (that for me at
least) it was worth it because it left an enduring impression on those of us
that had the privilege to use the system.

~~~
allenbrunson
Unfortunately, I didn't do much to move BeOS further down the field. By the
time I got there, the company had given up on BeOS as a standalone consumer
product and was squarely focused on BeIA, specifically the Sony eVilla. (you
can google it for the whole sad, sordid tale, if you dare.)

My contribution to the ecosystem, if in fact I ever made one, was to write
what I thought of as the best USENET newsreader available on the platform.

[http://www.platinumball.net/pineapple/news/beos/](http://www.platinumball.net/pineapple/news/beos/)

I definitely would still be using BeOS today, as my day-to-day OS, if that
were remotely possible, in this day and age.

~~~
qubex
I remember using that. I think I even registered.

