Scripting Client

Arriving late to the party, just want to add “what he said!” With respect to several comments, like “solution looking for a problem”, “programmers who did not add scripting to their applications.” My impression is, someone thought it would be great to have scripting for free, via OOP inheritance, and we got something not terribly useful. Too few BeOS users had inherited the scripting skills from AmigaDOS, so there was never any pressure on application developers to add meaningful scripting interfaces. And Rexx is an exceptionally versatile language for that particular use.

The only application I’ve ever had a real wish to address with scripting is WebPositive. Picture, for example, if you could work with a form, through the browser.

2 Likes

How is one supposed to know about this magic ‘Tall’ command?

Just grep the sources, Luke!

The power of open source. :slight_smile:
I know there’s a “Close all” menu item when you hold SHIFT and look in a Tracker window’s “Window” menu. So I look for "Close in src/kits/Tracker/ and find ContainerWindow.cpp#1830.
Here I see the BMessage being sent from that menu item is kCloseAllWindows. Clicking on that I find const uint32 kCloseAllWindows = ‘Tall’ which reveals the 4-byte magic token to hey Tracker with.

That’s really a hack, abusing hey to send a custom BMessage. We should rather have Tracker expose a proper scripting interface with user understandable commands, that getsuites would list.

1 Like

Sounds like a killer utility app in the making, aptly named Script-O-Matic :sunglasses:

Now the question is… who is going to build it?

Hey Tracker quit is documented for a user, hey Tracker 'Tall" isn’t. The former will always work, there is no assurance that the latter will. We’re talking about users who wish to automate a task, that’s who would use hey, not programmers.

A couple of followup remarks: First, it looks like there may be something lacking in my patch to ScriptWorld… It worked fine when I first tried it, but I wanted to play again. ATM, it starts up (in the Deskbar) but no window opens!. I’ll reboot in a while and try again, but I have no idea right now.

Humdinger, did you actually verify that ‘Tall’ works? I don’t want to close all my windows and then have to reopen them, so I haven’t tried it, but I picked out some others that I’d think would work and got nothing.

However, as AGMS points out, Tracker actually has some added scripting commands. I can’t get hey to do anything with them either. I’m not particularly good with hey, though, so maybe I’m not doing it right.

Well, I didn’t have to reboot. When I tried before, I was running MusicWeaver – with a lot of windows open! Seems that ScriptWorld doesn’t like that, and just gives up. As soon as I closed MusicWeaver I was able to run ScriptWorld as normal. The fact that there’s no scrollbar on the window is pretty clunky, too. I guess the app can use a little more TLC.:slight_smile:

Incidentally, are the hey docs available anywhere for the normal Haiku user? hey seems to be in bin by default, but I can’t find any relevant README. (I have it on my old BeOS machine, though.)

As an example of my difficulties, a “hey Tracker getsuites” shows the possible:

      Folder   B_CREATE_PROPERTY B_GET_PROPERTY B_EXECUTE_PROPERTY   DIRECT   RREF 
               Usage: create Folder to path # creates a new folder
              get Folder to path # get Tracker window pointing to folder
              execute Folder to path # opens Tracker window pointing to folder

so I tried some hey commands:

‘hey Tracker get Folder to “/boot/home”’

just seems to return an empty reply.

from the above, I’d have thought (as I eventually found that “do” is hey’s “execute”)

'‘hey Tracker do Folder to “/boot/home”’

should open that folder’s window, but again, nothing happens.

Am I just lost somewhere?

I never got these Tracker things to work either, I think this is used very rarely and it got broken at some point. Or maybe I’m also missing some special trick.

Sure. You asked how I got to the BMessage constant and I just answered… :slight_smile:

It’s a bit hacky, and breaks should the constant ever change, but so is deleting named attributes. Sometimes it’s enough to have a hacky but quick solution, and some people may appreciate to find out how to get to the magic word to invoke any menu/button/etc.

It’s a bit case sensitive (doesn’t have to be). So use the spelling hey Tracker getsuites shows.

These work, no extra arguments needed:

hey Tracker delete Trash (empties the trash)
hey Tracker do Preferences (pops up the preferences window)

The folder operations didn’t document their arguments well, had to read the source code at TrackerScripting.cpp « tracker « kits « src - haiku - Haiku's main repository and they still don’t work. For example:

hey Tracker get Folder to file /boot/home

Gets into the scripting code, but somehow has lost the extra argument with the file name (actually passed as a reference due to the “file” word), and thus does nothing.

There’s a BMessage print statement in there, showing that someone was debugging it at some time in the past. You can see the output if you do launch_roster stop x-vnd.be-trak and then in a different terminal window start Tracker manually so you can see the output with /boot/system/Tracker & It prints out your scripting attempts only if they get through to the Folder code.

Hmmm, BeOS OpenTracker is the same (it only has the create Folder one), the Folder operation is broken there too.

Is there any API documentation on how to make a Haiku app script-able?

I’m now suspecting that this is hey’s fault.

I was playing with “hey Tracker…” on BeOS (where Tracker only purports to have the CREATE option for Folder), and there hey (v1.2.5) prints out the message it’s sending. This is what I see:

>hey Tracker create Folder to “/boot/home/TEMP”
Send BMessage(B_CREATE_PROPERTY):
“specifiers” (B_MESSAGE_TYPE) : what=B_DIRECT_SPECIFIER
“property” (B_STRING_TYPE) : “Folder”
cur_specifier” (B_INT32_TYPE) : 0 (0x00000000)

Reply BMessage(B_REPLY):

If I’m parsing that correctly, it looks as if the ‘path’ just disappears.
Can’t persuade the Haiku hey (v1.2.8) to do a similar printout. Nor can I figure out what its ‘-o’ option is supposed to do.

Yes.

The Be Book has an introduction to it:
https://www.haiku-os.org/legacy-docs/bebook/TheApplicationKit_Scripting.html

There is probably also some information in Be Newsletters and old talks from BeOS engineers, but that may require digging into the web archive.

1 Like

Probably because you were using a version of Hey built with the debug option hey.cpp « bin « src - haiku - Haiku's main repository look for the line like:
#define DEBUG_HEY 0 // 1: prints the script message to be sent to the target application, 0: prints only the reply

The -o option outputs just the value of the result of the scripting operation, if it is a well known data type (integer, string, etc). If the answer is 42, it prints 42 rather than the whole BMessage structure. Useful for feeding in to bash scripts.

I guess. Can’t be bothered to recompile ATM, but the 1.2.5 version works in Haiku.

And the problem definitely seems to be a deficiency in hey. I tried two similar command lines, the first --using ‘create’ – supposedly correct, and the second --with ‘set’ – not actually permitted by the suite:

/boot/home/Desktop>hey Tracker create Folder to boot/home/TEMP/ABCD"
Send BMessage(B_CREATE_PROPERTY):
   "specifiers" (B_MESSAGE_TYPE) : what=B_DIRECT_SPECIFIER
       "property" (B_STRING_TYPE) : "Folder"
   "_cur_specifier_" (B_INT32_TYPE) : 0 (0x00000000)
Reply BMessage(B_REPLY):
/boot/home/Desktop>hey Tracker set Folder to "/boot/home/TEMP/ABCD"
Send BMessage(B_SET_PROPERTY):
   "specifiers" (B_MESSAGE_TYPE) : what=B_DIRECT_SPECIFIER
       "property" (B_STRING_TYPE) : "Folder"
   "_cur_specifier_" (B_INT32_TYPE) : 0 (0x00000000)
   "data" (B_STRING_TYPE) : "/boot/home/TEMP/ABCD"
Didn't understand the specifier(s) (error 0x80002008)

With ‘set’, the data value is included, but ‘create’ just ignores it.

Playing further with ScriptWorld, too, I find that it has no way of providing a data value for any specifier type. So not much use for anything practical right now.

One general obstacle with hey, I think, is that Scripting Messages and the Command Line are a bit like strawberries and ketchup… They don’t go well together! I’d think it would be more useful to have some kind of structured text format for input – XML or JSON, say. (For response output, too, maybe.)

One possible route would be to do as I did with gadgeteer (for command-line presentation of GUI panels) and just put JSON in the command line. It works well, but seems to frighten people. :grinning: Alternatively just have input from a file/standard input.

Seems to me that Scripting needs a lot of attention if it’s to see much general use. Not sure if I’m motivated to think about it yet. As Donn said earlier: “My impression is, someone thought it would be great to have scripting for free, via OOP inheritance, and we got something not terribly useful.”

After a little more reflection, I realize that, as the point of a scripting facility is to be able to write scripts (!), what we really need to have is some interface libraries for our existing scripting languages. Python, of course, but also Ruby and maybe Lua. What else? Maybe a good student task?

REXX, of course. Because that’s how Amiga did it :smiley:
BeBREXX has its own scripting support but it is quite different and I’m not sure how far it can interoperate.

2 Likes