Include scripts via url?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lichtathlet
Posts: 6
Joined: 14 Oct 2019, 07:54

Include scripts via url?

16 Oct 2019, 07:17

Hi there!


I'm working on some script for a group of friends and I'm stuck when it comes to include script from urls.

Since not everybody in the group wants the same functions, I split the script into multiple parts and include them
in a script file per user.

for instance

; custom user settings

1st function
2nd function
3td function

; include global scripts

#include /folder/global.ahk
#include /folder/keymappings.ahk
#include /folder/screenshots.ahk
...

this works with local files but I don't want to edit the same files 20 times for each user everytime I update a script.
So I thought I put all scripts in a google drive folder and include the single scripts via their sharing urls

for instance

#Include https drive.google.com /open?id=1M75f_H1R7G1kDD-oaK-z7L9-4aAX (not a real url - just for demonstration)

but AHK doesn't seem to like urls to include.

Are there any other ways to achieve this?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Include scripts via url?

16 Oct 2019, 08:48

u cant dynamically include files. standard include requires the files be known at compile time.
u could either design ur scripts in a way such that they can be run on their own as standalone scripts
or u could devise a crude app launcher that will download the contents of these scripts and stitch them together into a new script and run that

but why do all this, just use ahkh. it supports dynamic includes
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Include scripts via url?

16 Oct 2019, 08:53

Try this:

Code: Select all

url := "https://content.screencast.com/users/teadrinker/folders/Files/media/48dc67fe-ccb3-48dc-9504-2fce8caae632/ScriptFromURL.ahk"

whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", url, false)
whr.Send()
status := whr.status
if (status != 200)
   throw Exception("Failed to download the script, status:" . status)

body := whr.responseBody
pData := NumGet(ComObjValue(body) + 8 + A_PtrSize)
length := body.MaxIndex() - body.MinIndex() + 1
text := StrGet(pData, length, "utf-8")
text := SubStr(text, 2)

ExecScript(text, A_AhkPath)

ExecScript(script, exePath)  {
   shell := ComObjCreate("WScript.Shell")
   exec := shell.Exec(exePath . " *")
   exec.StdIn.Write(script)
   exec.StdIn.Close()
   return exec.ProcessID
}
User avatar
Cuadrix
Posts: 236
Joined: 07 May 2017, 08:26

Re: Include scripts via url?

17 Oct 2019, 06:48

Isn't that basically the same as UrlDownloadToFIle @teadrinker ?
User avatar
Chunjee
Posts: 1499
Joined: 18 Apr 2014, 19:05
Contact:

Re: Include scripts via url?

17 Oct 2019, 08:53

Here is an example of how I checked the compiled app's version and downloaded the latest copy if it didn't match a gist version number:
https://github.com/Chunjee/LoneIRC/blob/master/app.ahk#L73-L96

It could certainly be improved. looking at this now, if the download failed, the user's old exe would no exist anymore in the same dir.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Include scripts via url?

17 Oct 2019, 11:30

Cuadrix wrote: Isn't that basically the same as UrlDownloadToFIle @teadrinker ?
No, UrlDownloadToFIle saves data to the file, while my example does not, but launches code from memory. Of course this is nor the same as #Include since code is launched as a new process, but sometimes this can be an acceptable way.
Lichtathlet
Posts: 6
Joined: 14 Oct 2019, 07:54

Re: Include scripts via url?

18 Oct 2019, 03:41

hey guys, thanks for the input. I'm still pretty new, so a lot of this is very hard to understand for me.

I tried URLDownloadToFile

but it only worked with the first file in my script

i set up the scripts in modules in this order:

<download groupads.ahk>
< custom user variables>
<download global.ahk>
<download keymappings.ahk>
...

The groupads file gets downloaded but nothing else.
I also can't move the groups up in the script because then the custom variables don't get recognized anymore
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Include scripts via url?

18 Oct 2019, 04:01

Could you simply store your files on a cloud drive and run that?
I am asking just in case your scenario could benefit from it and you didnt think of it.

For example: having OneDrive folder that sync between one or more of your computers can solve an issue like that quite easily.
But it might be impractical if using public computers.
Lichtathlet
Posts: 6
Joined: 14 Oct 2019, 07:54

Re: Include scripts via url?

18 Oct 2019, 07:27

yes, that would totally work but unfortunately I guess not everybody is down to that solution :cry: (some old people in the group)
that's why I was looking for a more convinient solution.
KingPresLii
Posts: 13
Joined: 29 May 2022, 16:20

Re: Include scripts via url?

24 Oct 2022, 06:52

@teadrinker Hi. This post is really old but I want to undersdand you script example. Can you add comments about what its does? thank you
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Include scripts via url?

24 Oct 2022, 11:01

To understand what's going on here, you should have a basic knowledge about scriptable COM objects. If you haven't, some info is here.
I used two COM objects: WinHttp.WinHttpRequest.5.1 (MSDN, AHK forum) and WScript.Shell (MSDN, AHK forum). First one was used to download the script text from the server, second one to launch the script. I don't see a point to comment line by line, you can read all info in the links I've provided. If more specific questions appear, feel free to ask and I'll try to answer.
KingPresLii
Posts: 13
Joined: 29 May 2022, 16:20

Re: Include scripts via url?

25 Oct 2022, 03:33

@teadrinker
I do understand now thanks for the info. Till next time. :D
KingPresLii
Posts: 13
Joined: 29 May 2022, 16:20

Re: Include scripts via url?

25 Oct 2022, 11:06

owwww! heres a legit question i guess. idk Im not an expert. it doesnt work with feiyues encyption. i searched bt cant find any solution. is there a posible way to make it work?.? I also change some part of Feiyues encryption but doesnt work. it says at na first line #NoEnv doesnt recognized by ahk.
KingPresLii
Posts: 13
Joined: 29 May 2022, 16:20

Re: Include scripts via url?

25 Oct 2022, 11:20

@teadrinker
Heres I really wanted to do. I really want to hide my script and searched all over ahk then i came up with your script which is very helpful to me cause i really want to load my main script online but also i want my main script to be encrypted. I know its not 100% safe but atleast i want to do something that it wont be decrypt or steal my script by free decypting tools etc. is there a way to let ahk do that ?? im sorry if it confuse you. english is not my first laguage.
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: Include scripts via url?

28 Oct 2022, 12:25

KingPresLii wrote: i want my main script to be encrypted
See this example. You can download encrypted text and then decypt it and run.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: emp00, Google [Bot] and 172 guests