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?
Include scripts via url?
-
- Posts: 6
- Joined: 14 Oct 2019, 07:54
-
- Posts: 1472
- Joined: 05 May 2018, 12:23
Re: Include scripts via url?
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
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
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Include scripts via url?
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
}
Re: Include scripts via url?
Isn't that basically the same as UrlDownloadToFIle @teadrinker ?
Re: Include scripts via url?
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.
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.
Re: Include scripts via url?
Came across https://www.autohotkey.com/boards/viewtopic.php?f=6&t=6565 by coincidence which I also think is relevant to your challenge.
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Include scripts via url?
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.
-
- Posts: 6
- Joined: 14 Oct 2019, 07:54
Re: Include scripts via url?
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
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
Re: Include scripts via url?
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.
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.
-
- Posts: 6
- Joined: 14 Oct 2019, 07:54
Re: Include scripts via url?
yes, that would totally work but unfortunately I guess not everybody is down to that solution (some old people in the group)
that's why I was looking for a more convinient solution.
that's why I was looking for a more convinient solution.
-
- Posts: 13
- Joined: 29 May 2022, 16:20
Re: Include scripts via url?
@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
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Include scripts via url?
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.
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.
-
- Posts: 13
- Joined: 29 May 2022, 16:20
Re: Include scripts via url?
@teadrinker
I do understand now thanks for the info. Till next time.
I do understand now thanks for the info. Till next time.
-
- Posts: 13
- Joined: 29 May 2022, 16:20
Re: Include scripts via url?
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.
-
- Posts: 13
- Joined: 29 May 2022, 16:20
Re: Include scripts via url?
@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.
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.
-
- Posts: 4412
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Include scripts via url?
See this example. You can download encrypted text and then decypt it and run.KingPresLii wrote: ↑i want my main script to be encrypted
Who is online
Users browsing this forum: Bing [Bot], Chunjee, Descolada, GroggyOtter, moltenchees and 167 guests