Use ChatGPT to comment your AppleScript code

Here is a interesting approach.

Ask ChatGPT to add comments to your AppleScript code:
We ask: add comment to this AppleScript code:

ex. This is the AppleScript we like ChatGPT to add comment to.

tell methodCall
	its methodName:"chatgpt_call" params:{"trafic light in arduino"}
end tell

script methodCall
	on methodName:methodName params:params
		tell application "http://localhost:7080"
			call xmlrpc {method name:methodName, parameters:params}
		end tell
	end methodName:params:
end script

We return this from ChatGPT

This AppleScript code is making an XML-RPC call to an HTTP server at http://localhost:7080 with a method name of “chatgpt_call” and a single parameter of “trafic light in arduino”. The code defines a script object called methodCall that defines a handler called methodName that takes a method name and a list of parameters and sends an XML-RPC call to the specified server using the supplied method name and parameters.

1 Like

That’s not a comment in the sense that it would explain anything to a non-initiated. It’s just code turned into prose. A real comment (i.e. a useful one) would let the reader know what (for example) the methode chatgpt_call is doing with its parameter.

And how will ChatGPT know that?. its only an post request with parameters

To know what you are asking for. My code example also need the code for the server and its function to know the response. So ChatGPT could only response to what I give it. And it did it very well. I have used ChatGPT for other technology description and its very accurate.

I didn’t question its accuracy. I questioned its usefulness in this context.

The author of the code didn’t explain what the message is supposed to do. And this message is the only unclear part of the whole thing. So the code is incomprehensible.

By which I do not mean the technical aspects, they are cristal clear. Especially since it is written in AppleScript, which is overly verbose. But the intention is completely obscure. Nobody with a minimum of programming knowledge needs code turned into prose (or a poem, for that matter). But they’d need helpful information. So, doubling code size by simply repeating what is already there does not help. Not even if it’s done by the latest and greatest AI tool.

I’m well aware that it can’t know more than you let it know. Which again speaks against the usefulnes of it in this context. Nobody is any the wiser after reading this farce of a “comment”.

When you know its XMLRPC call then you could ask something else.

Lets ask ChatGPT: what is xmlrpc call with parameters

XML-RPC (XML Remote Procedure Call) is a protocol that enables remote procedure calls over HTTP. It uses XML to encode the request and response data.
To make an XML-RPC call with parameters, you need to first construct an XML document with the necessary data. The XML document should have a methodCall element that contains a methodName element and a params element. The methodName element specifies the name of the remote procedure you want to call, and the params element contains one or more param elements, each of which specifies a parameter for the remote procedure.

Here’s an example XML document for an XML-RPC call with two parameters:

In this example, the method name is “example.method” and there are two parameters: a string parameter with the value “param1_value” and an integer parameter with the value 123.
You would then send this XML document as the body of an HTTP POST request to the server that implements the remote procedure. The server would then parse the XML document and execute the specified remote procedure with the given parameters.

And if that is not enough

Lets ask ChatGPT: give me example in python how to make xmlrpc server

Sure, here’s an example of how to create a simple XML-RPC server in Python using the built-in SimpleXMLRPCServer module:

In this example, we define a simple function add that takes two arguments and returns their sum. We then create an instance of SimpleXMLRPCServer and bind it to the address "localhost" on port 8000.

We register our add function with the server using the register_function method, which takes two arguments: the function itself, and a string representing the name of the function as it will be called by XML-RPC clients.

Finally, we start the server using the serve_forever method, which listens for incoming XML-RPC requests and dispatches them to the appropriate function.

To test the server, you can use the built-in xmlrpc.client module to make a remote procedure call to the add function:

In this example, we create a ServerProxy object representing the remote XML-RPC server at the address http://localhost:8000/ . We then call the add function on the remote server with arguments 4 and 5 , and assign the result to a variable result . Finally, we print the result, which should be 9 .

Its enough to me to give a good start to make a implementation of XMLRPC call in AppleScriptObjC if that is my goal.

It’s vastly enough. I was not arguing that chatGPT can’t create arbitrary amounts of text. As can you. I was arguing that it does not write a comment that is anything else than a summary of the code it sees.

But now your goal is no longer to have it produce a comment, it is suddenly to write an XMLRPC call in AS. Which by now even cursory visitors of this forum know how to do given your efforts…

Let’s put that down to: chatGPT can easily outproduce any human in writing text. I dont care one way or another. Write your code with it, write your comments with it. Whatever floats your boat. But don’t force me to believe that it’s any kind of genius.

And it doesn’t help to be negative ask yourself ‘what are you giving instead’.
I thought I could teach you what XMLRPC is… you didn’t know that 3 days ago.

Once again: don’t patronize me. I knew what XMLRPC is. I knew what SunRPC was. I never asked about the meaning of it, much less did I ask you.

I don’t know why anybody would want to throw the same technology at each and every problem. Much less, if that person does not explain why this technology is useful in a particular context, nor what the context even is. We all can churn out code. Even ChatGPT can. The interesting part is not this, but explaining why the code is tackling a specific problem in a specific way. And, of course, what this problem even is.

If iI wanted to know the meaning of an acronym, I’d throw it at a search engine.

For any protocol there is rules and guidelines how a communication is made. If an implementation do not follow the rules or guidelines the response will return error. Every protocol and there is many use different rules and guidelines. If there is a standard it doesn’t mean every Implementation use the standard but instead use custom Implementation.

In the past python didn’t have support for async io application. In other words event loops run asynchronous tasks and callbacks, perform network IO operations, and run subprocesses.

The module Twisted made it possible to make event-driven application to run function in event-loop. The reactor class in Twisted is the method that make event-loop possible. Modern python do not need Twisted to do this anymore. Python become more and more a approach to build server or back-end to other front-end for web technology. Why would it be less useful to use Python and AppleScript together. Or to take advanced of powerful library/modules it provide. Sure people could have excuses to not learn Python. That is little pity when the documentation include sample code is so great. In other words its very easy to find solution to almost anything in Python. There the user could read the code and understand it.

AppleScript is a scripting language made for Automation of Desktop application. At least that was the core idea/goal from the early days. Automation is a word that could mean different things in different context.