Please login or register.

Login with username, password and session length
Advanced search  

News:

Pages: [1]   Go Down

Author Topic: Applescript and JSON data in OS9?  (Read 7507 times)

Y2K

  • 16 MB
  • ***
  • Posts: 23
  • New Member
Applescript and JSON data in OS9?
« on: July 17, 2021, 05:41:50 AM »

On my main machine, I have some Applescripts that employ a shell script to send/fetch some JSON data either in the local network, or from the internet. Through some trial and error, I managed to translate it for my G4 machine that runs Leopard. However, I'm having trouble translating it to OS 9, and I'm not sure if what I'm trying to do is even possible with an early version of Applescript, as I'm new to OS9. I don't think the JSON messages themselves are the issue, it's the final phase where I'm supposed to post the constructed message, but Mac OS 9 probably doesn't understand shell script commands.
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4668
  • just a number
Re: Applescript and JSON data in OS9?
« Reply #1 on: July 17, 2021, 09:36:51 AM »

MacOS9 does not even know what a shell is. :)

applescript itself is also like 15% different from OSX.
Logged
insert arbitrary signature here

Y2K

  • 16 MB
  • ***
  • Posts: 23
  • New Member
Re: Applescript and JSON data in OS9?
« Reply #2 on: July 17, 2021, 09:43:50 AM »

MacOS9 does not even know what a shell is. :)

applescript itself is also like 15% different from OSX.


Yup, that's exactly what I noticed. Hence, I wonder how this used to be done, if it was. JSON seems to be from the early 2000s and is useful for applications that don't go obsolete.
Logged

teroyk

  • 512 MB
  • *****
  • Posts: 623
  • -
Re: Applescript and JSON data in OS9?
« Reply #3 on: July 17, 2021, 10:55:27 AM »

Lets try convert that shell script to Applescript. Can share that shell script?
Logged

Y2K

  • 16 MB
  • ***
  • Posts: 23
  • New Member
Re: Applescript and JSON data in OS9?
« Reply #4 on: July 17, 2021, 12:40:11 PM »

Lets try convert that shell script to Applescript. Can share that shell script?
Okay, the gist of it is below.
I'm not sure if this forum has specific formatting for code or not, Classilla doesn't show any of the formatting options!

####
set theSetting to "some stuff that's being sent"
set theDestination to "some address where stuff is being sent"
do shell script "curl --request PUT --data " & theSetting & " " & theDestination
Logged

teroyk

  • 512 MB
  • *****
  • Posts: 623
  • -
Re: Applescript and JSON data in OS9?
« Reply #5 on: July 18, 2021, 12:52:14 AM »

Lets try convert that shell script to Applescript. Can share that shell script?
Okay, the gist of it is below.
I'm not sure if this forum has specific formatting for code or not, Classilla doesn't show any of the formatting options!

####
set theSetting to "some stuff that's being sent"
set theDestination to "some address where stuff is being sent"
do shell script "curl --request PUT --data " & theSetting & " " & theDestination

Ok...curl manual says:
"--request <command>
              (HTTP) Specifies a custom request method to use when communicat-
              ing with the HTTP server.  The specified request  will  be  used
              instead  of  the  method otherwise used (which defaults to GET).
              Read the HTTP 1.1 specification for  details  and  explanations.
              Common  additional  HTTP  requests  include  PUT and DELETE, but
              related technologies like WebDAV offers PROPFIND, COPY, MOVE and
              more.
--data <data>
              (HTTP) Sends the specified data in a POST request  to  the  HTTP
              server,  in  the  same  way  that a browser does when a user has
              filled in an HTML form and presses the submit button. This  will
              cause curl to pass the data to the server using the content-type
              application/x-www-form-urlencoded.
"
So basically that shell script sends "some stuff" to "some address" via http-protocol.

I know that sending files over network is possible with AppleScript, but is there somebody that have done this kind of AppleScript and can help you?
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4668
  • just a number
Re: Applescript and JSON data in OS9?
« Reply #6 on: July 18, 2021, 10:17:53 AM »

Yup, that's exactly what I noticed. Hence, I wonder how this used to be done, if it was. JSON seems to be from the early 2000s and is useful for applications that don't go obsolete.

i dont know what your application is, from my perspective json is just another text based interchange (file) format.

so to edit "jsons" you should be able to use any language which supports sprintf and regexp in some form, from php and perl over max/msp or realbasic to c++.

dedicated core services for such things simply did not exist in OS9, all it has is a handful of extensions such as stuff it engine or UTF conversion, but they are not for the user.

eventually you might find a solution using a program like dreamweaver, but i have no idea if it is apple-scriptable.

i have no idea about anything releated to javascript either.

there are also online tools for simple conversions. of course they probably dont work from OS9. https://jsoneditoronline.org/
Logged
insert arbitrary signature here

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4668
  • just a number
Re: Applescript and JSON data in OS9?
« Reply #7 on: July 18, 2021, 10:19:39 AM »

ah, http version available: http://jsoneditoronline.org/
Logged
insert arbitrary signature here

Y2K

  • 16 MB
  • ***
  • Posts: 23
  • New Member
Re: Applescript and JSON data in OS9?
« Reply #8 on: July 18, 2021, 11:33:48 AM »

i dont know what your application is, from my perspective json is just another text based interchange (file) format.
So basically that shell script sends "some stuff" to "some address" via http-protocol.

Yes indeed.
And I believe the text format is basically the same as XML: You have some key that contains a value, and you can use GET command to read that value, or POST or PUT to change the values of those keys, unless they're read-only. One of the most typical uses of JSON is weather data: If you have a weather app, it fetches the data from some server's plain text XML file, and the app itself decides what sort of weather status icon to use in the graphical interface, for example. Or what number to show in the bit of the code where temperature should show up. I think you can probably fetch pictures with JSON too, but most uses (and my requirement) is for the plain text only.
If we could crack this, this might honestly bring quite a lot of new functionality to OS 9 because if it doesn't like to open sites from the world wide web, it could still fetch the raw data and do something with it in a way that it's able to. JSON has very wide applications, and plain data like that is quick to download because you're usually only asking for the value of some specific key, in plain text. And then you can use that variable to do if-this-then-that stuff, if you like.

I know that sending files over network is possible with AppleScript, but is there somebody that have done this kind of AppleScript and can help you?
That's what I'm hoping to find out. I have no idea how many people here for example use Applescript. It has existed for a long time but even if you had been a Mac expert for decades, it doesn't automatically mean that you want to learn to script, as it's an extra. So Applescripters are probably a small subset of all the users.

so to edit "jsons" you should be able to use any language which supports sprintf and regexp in some form, from php and perl over max/msp or realbasic to c++.
there are also online tools for simple conversions.
Indeed, JSON can be handled by any programming language that can send a command like that to the network. I've already cracked how to create the actual contents of the message, i.e how to get it to a format that the destination understands. It's slightly tricky with Applescript because JSON involves quotation marks, which already have a special meaning in Applescript; You have to escape the quotes by using backsplashes with them, and then redefine the message to a "quoted form of itself" before attempting to post it. But it currently works on my two OS X machines, the early and the modern one. Took some adjustments, but it could be translated.

eventually you might find a solution using a program like dreamweaver, but i have no idea if it is apple-scriptable.
Hmm, that's an interesting approach. I've never done Flash and I've never used Dreamweaver, but if it turns out that Applescript of the time absolutely can not do what I'm thinking here, then it might be worth exploring if Dreamweaver can send and receive those commands... So I guess it would mean making a local web page that works a bit like an application interface. Which is supposedly easier than writing an actual standalone application from scratch, unless you already know how to write applications. Which I don't.
Logged

IIO

  • Staff Member
  • 4096 MB
  • *******
  • Posts: 4668
  • just a number
Re: Applescript and JSON data in OS9?
« Reply #9 on: July 18, 2021, 04:00:26 PM »

since i am not a javascript/java person, i mentioned dreamweaver because it might at least be able to display a somewhat useful color highlighting or however that is called.

taking something from elsewhere and then making it ready for web applications seems to be one of the main thing which is done with that format.

it is also used for presets or as meta fileformat from many programs, in a similar manner like xml. err... but not on OS9. :)

what you are using it for? (since there are no programs for it in OS9?)
Logged
insert arbitrary signature here

Y2K

  • 16 MB
  • ***
  • Posts: 23
  • New Member
Re: Applescript and JSON data in OS9?
« Reply #10 on: July 20, 2021, 02:24:07 PM »

since i am not a javascript/java person, i mentioned dreamweaver because it might at least be able to display a somewhat useful color highlighting or however that is called.
I don't really need to view the JSON data per se;
The messages to send would be embedded into the Applescript, and sometimes what messages it sends depends on an answer it gets when using JSON to fetch for the value of some specific key, first. So the reactions would already be programmed in. But if Applescript isn't an option, Dreamweaver might still be able to send just the commands, if unable to fetch data or have "conversations" with the data server, like Applescript would.

what you are using it for? (since there are no programs for it in OS9?)
Controlling a smart lighting system, which of course simply wasn't a thing back in the day. It wasn't a thing even in the G4 days but my G4 is controlling the system anyway, thanks to Applescript. I normally do 100% of the lighting control from my main computer because I loathe apps and they can't come anywhere near the sophistication I can build with Applescripts. And once I learned how to use JSON + Applescript to control the lighting, it was easy to extend JSON usage to also fetch space weather satellite data and local weather data to contribute to the end result, how the script deduces what "appropriate lighting" means. For example, whether it's a cloudy autumn day or a summer day with the sun shining right in makes a very big difference. Or, if it's cloudy or the sun hasn't set yet, then I don't care what's going on with space weather because I wouldn't be able to see it anyway.
The scripts on my main machine are incredibly complex and often employ external .plist files to store data, like "settings", and I definitely don't expect to translate all that to the OS9, and not even to the G4. But you know, as I tend to use the OS9 laptop or the G4 in a different room than where my main machine is, I would like to be able to do the basic adjustments from there, and do a basic checkup on the space weather conditions, without having to leave and go wake the main machine from sleep. A sort of "script suite lite".
Logged

DrNo7

  • 64 MB
  • ****
  • Posts: 98
Re: Applescript and JSON data in OS9?
« Reply #11 on: July 20, 2021, 10:25:02 PM »

As your AppleScript in OSX depends on curl for the HTTP PUT transaction, it is reasonable to assume that AppleScript does not contain a simple way to do do (so the same should be true with the OS9 version).
However, it does illustrate also that AppleScript is good at delegating/piloting another application for a specific action. I do not know if there is a network transfer application that could be driven by AppleScript for this need. But if you are open to alternatives in the scripting realm, you can leverage MacPerl (I do not know if there was any MacPython?). Even if you are not fluent in perl, it should be possible to write a short perl script doing the equivalent of the curl command and replace in the AppleScript the command block calling curl with a tell MacPerl to run script X.

If you think it could be a viable alternative but Perl sounds like Chinese to you, I can give you a hand and try to guide you on installing any missing Perl module (I never checked the latest version of Perl in MacPerl nor which modules are bundled by default).
Logged
Ti 1 GHz / 1 GB / FW SSD / Airport Extreme PCMCIA (triple boot)
Alu 12 1.5GHz / 1.5 GB / 256 GB mSata SSD (dual boot for now)

teroyk

  • 512 MB
  • *****
  • Posts: 623
  • -
Re: Applescript and JSON data in OS9?
« Reply #12 on: August 24, 2021, 08:32:15 AM »

I found some information how to get/send files over net with Applescript with MacOS8-OS9.2.2
But you need first program called Marionet and problem is that it has same
name that security hole in modern browsers...so it can be hard to find.
But this information is from Macmaailma magazine from 2/1998, sorry I translate it later (maybe)
it is in finnish (that TM is that TM-char):
"

Marionet

Marionet on näppärä skriptattava internetohjelma, jolla ei ole omaa käyttöliittymää lainkaan. Marionettia voi käyttää ainoastaan muista ohjelmista AppleEventien kautta. Alla oleva ohjelma hakee annetun tiedoston ftp-palvelimelta (ftp.mad.fi) omalle levylle (Saukko).

tell application "MarionetTM"
 session begin set sessionID to the status text of the result as integer
 get ftp file sessionID url "ftp.mad.fi/pub/HauskaaJoulua.Moov" local path "Saukko:Joulua.Moov" transfer type "binary" file signature "????????" user "" password "" account ""
 session end sessionID
end tell

Automatisoimalla internet-toimintoja voi kerätä vaikkapa ”päivänlehden” itselleen ja lukea sen sitten nopeasti omalta kiintolevyltään. Alla olevassa esimerkissä imaistaan Macmaailman www-sivu omalle työpöydän kansioon ”Imettyä”. Samalla voitaisiin tuottaa HTML-sivu ja lisätä imetyt sivut listaan, jossa olisi linkit imettyhin tiedostoihin.

tell application "MarionetTM"
 session begin
 set sessionID to the status text of the result as integer
 get http file sessionID url "www.mad.fi/index.html" part "BODY" local path "Saukko:desktop folder:Imettyä:Macmaailma.html"
 session end sessionID
end tell

"

I think if you find that Marionet manual, then there might be all answers to how to send wtih it.

EDIT: and those  ??? -faces are 3 x ?-chars
EDIT2: first list get file with ftp and second get file with http
« Last Edit: August 24, 2021, 08:44:18 AM by teroyk »
Logged
Pages: [1]   Go Up

Recent Topics