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

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
danielrr
Posts: 142
Joined: Mon Mar 04, 2013 4:03 pm

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

Post by danielrr » Mon Oct 24, 2022 7:50 pm

Is there a way to use LC's "send to program" (on a Mac) to first open then download a WebPage providing the URL?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Mon Oct 24, 2022 8:51 pm

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
Last edited by dunbarx on Tue Oct 25, 2022 12:12 am, edited 1 time in total.

danielrr
Posts: 142
Joined: Mon Mar 04, 2013 4:03 pm

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

Post by danielrr » Mon Oct 24, 2022 9:27 pm

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)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Mon Oct 24, 2022 9:59 pm

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")
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » 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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Tue Oct 25, 2022 12:30 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 3060
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Tue Oct 25, 2022 12:44 am

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...

danielrr
Posts: 142
Joined: Mon Mar 04, 2013 4:03 pm

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

Post by danielrr » Tue Oct 25, 2022 12:57 am

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…

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Tue Oct 25, 2022 1:43 am

How can AppleScript be used to trigger JavaScript functions inside of a web page?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 3060
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Tue Oct 25, 2022 8:15 am

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.

danielrr
Posts: 142
Joined: Mon Mar 04, 2013 4:03 pm

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

Post by danielrr » Tue Oct 25, 2022 10:00 am

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)

stam
Posts: 3060
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Tue Oct 25, 2022 12:57 pm

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.
Last edited by stam on Wed Oct 26, 2022 10:47 am, edited 1 time in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Tue Oct 25, 2022 4:47 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

stam
Posts: 3060
Joined: Sun Jun 04, 2006 9:39 pm

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

Post by stam » Tue Oct 25, 2022 5:07 pm

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/

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

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

Post by FourthWorld » Tue Oct 25, 2022 11:52 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply