Page 1 of 1

Using "send to program" to open & download. webpage

Posted: Mon Oct 24, 2022 7:50 pm
by danielrr
Is there a way to use LC's "send to program" (on a Mac) to first open then download a WebPage providing the URL?

Re: Using "send to program" to open & download. webpage

Posted: Mon Oct 24, 2022 8:51 pm
by dunbarx
Hi.

"Send to Program" derives from Hypercard, where I used it extensively to communicate between machines on a network. The "program" I always was sending to was Hypercard itself.

It does not have the power that it once did, though. For my use, I had to consider sockets instead. What program would you think would be at the other end? Something like "send "openThis" to program "Safari" with "XURL"?

Craig

Re: Using "send to program" to open & download. webpage

Posted: Mon Oct 24, 2022 9:27 pm
by danielrr
Hi Craig,
What program would you think would be at the other end? Something like "send "openThis" to program "Safari" with "XURL"?
Exactly this. Send "OpenThis" to (a modern browser) with ThisURL

*and* then another instruction to download the uploaded page (which is a page created after a PHP request)

Re: Using "send to program" to open & download. webpage

Posted: Mon Oct 24, 2022 9:59 pm
by FourthWorld
To launch a browser to display a given URL:

Code: Select all

launch url "http://fourthworld.com"
To download a file from a web server:

Code: Select all

put url "http://fourthworld.com/products/devolution/4wDevo.livecode.gz" \
   into url ("binfile:/Some/Path/To/Local/File.extension")

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 12:14 am
by dunbarx
Richard.

In you opinion, then, what benefit does the "Send to Program" command still offer? I found it hobbled to say the least.

Craig

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 12:30 am
by FourthWorld
dunbarx wrote:
Tue Oct 25, 2022 12:14 am
In you opinion, then, what benefit does the "Send to Program" command still offer?
None. LC Ltd recommends launching URLs with the "launch URL" command.

AFAIK "send to <program>" and "answer program" were dependent on OS APIs only available in Mac Classic/Carbon, no longer maintained in current macOS. And being directly bound to Apple events, they're Mac-only anyway and therefore non-starters for any cross-platform use.

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 12:44 am
by stam
For mac-only development you can achieve quite a lot more with AppleScript, especially as there are many hooks into all sorts of apps and the OS.
LC does provide the do as syntax for this:

Code: Select all

do <script> as <alternateLanguage>
for example

Code: Select all

do  ("tell application" && quote & "Finder" & quote && "to activate") as "applescript"
There is a huge online resource for AppleScripts so for more complex tasks that LC doesn't cater for directly (eg integrating with iCal etc), and probably fills the gap for 'send to program' quite nicely...

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 12:57 am
by danielrr
Thanks so much, as always, Craig, Richrad, for your answers
dunbarx wrote:
Tue Oct 25, 2022 12:14 am
Richard.

In you opinion, then, what benefit does the "Send to Program" command still offer? I found it hobbled to say the least.

Craig
In my opinion, this is a nice example of the situation where you would appreciate something akin to the "Send to Program" command. By using the
put url "http://fourthworld.com/products/devolut ... ivecode.gz" \
into url ("binfile:/Some/Path/To/Local/File.extension")
you may get nothing useful from a page using JavaScript to load its content. But if you were able to tell the app to download the URL and then do something with it…

Now I'm pondering stam's (thanks to!! ) useful comments…

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 1:43 am
by FourthWorld
How can AppleScript be used to trigger JavaScript functions inside of a web page?

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 8:15 am
by stam
I mentioned AppleScript as a way to “send to a program” that is above and beyond a browser. A huge degree of automation is possible, but alas is MacOS only.
Having said that, I imagine you can control browsers to a higher degree than LC can.

Admittedly this doesn’t answer the OP which was to “download a page by providing a URL” [in LC]. No one would use AppleScript for that, although I’m sure it’s possible in the same way it is in LC (and FWIW I’m not sure “triggering JavaScript functions” was the specific question, unless you mean as part of loading the desired web page - in this would be done in the browser controlled by AS).

But I mentioned this as an alternative to a “send to program” generically, since the OS specified was MacOS.

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 10:00 am
by danielrr
FourthWorld wrote:
Tue Oct 25, 2022 1:43 am
How can AppleScript be used to trigger JavaScript functions inside of a web page?
I don't think you can (but I'm not an expert on AppleScript)

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 12:57 pm
by stam
How did triggering JavaScript functions enter the conversation?

FWIW:
- there is a “do JavaScript” command in AppleScript.
- for related conversations see here: https://forum.latenightsw.com/t/scripti ... script/996

Particularly in response to the OP if you wanted to go down the AppleScript route:
http://www.cubemg.com/how-to-extract-in ... plescript/

As I said, AppleScript is an often overlooked gem… but sadly MacOS only.

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 4:47 pm
by FourthWorld
stam wrote:
Tue Oct 25, 2022 12:57 pm
How did triggering JavaScript functions enter the conversation?
Daniel's been working at trying to get dynamically-rendered data from a site:
https://forums.livecode.com/viewtopic.p ... 54#p218540

Since the site is licensed under Creative Commons, it may be that they have a copy of the data available for download, or will add a REST API as they finish the site. Either would greatly simplify his task.

The way to find out would be to write them. I don't know if he's done that.

FWIW:
- there is a “do JavaScript” command in AppleScript.
LiveCode has a similar function built into the browser widget, allowing you to execute JavaScript within the page the widget displays.

AFAIK it works on every platform where the browser widget is available. But since that doesn't include modern Ubuntu I've never used it and don't recall the syntax for accessing that offhand. But I'd guess that a quick trip through the See Alsos of most browser widget entries in the Dictionary would turn that up quickly.

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 5:07 pm
by stam
Not arguing that for LC projects it’s easier to use LC commands.

Just mentioning as an alternative for other things.

But on the specific question of being able to do this with AS, please see the URL I linked above:
http://www.cubemg.com/how-to-extract-in ... plescript/

Re: Using "send to program" to open & download. webpage

Posted: Tue Oct 25, 2022 11:52 pm
by FourthWorld
It seems like a good tutorial, and likely a good starting point for the rich simulated interactions he'll need to get to the snippet he's looking for.

Or when he writes them he may find they've finished their open source repository and he can just have all the snippets he needs ready to go with no extra effort at all.

I guess we'll find out after he writes to them.