How to run script automatically when in exe form Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ctrl+shift+a
Posts: 5
Joined: 10 Dec 2017, 22:45

How to run script automatically when in exe form

10 Dec 2017, 23:16

Hi there ...

My first post into this forum, so hope I am within the guidelines of do's and dont's on the community.

I have a script - say xyz.ahk. This script does certain actions when the user presses ctrl+shift+p. It's all working fine. I would be distributing this script in the exe form (xyz.exe). Since I want to distribute the script to others, I have also coded the script to do the following ...

Code: Select all

Detect if it is being run for the first time (I detect it based on whether xyz.ini file exists or not)
if it is the FirstTime
{
  1) Show a welcome screen that tells the user about what the script does and to press ctrl+shift+p when required.
  2) Makes a shortcut of the xyz.exe into the user's startup folder.
  3) Get user's preferences and save in xyz.ini file.
}
This is also working fine. That is, when a user runs the xyz.exe on a PC for the first time, it does the first time actions. The problem is that the user still has to press ctrl+shift+p after double clicking the xyz.exe. That is, when the user double clicks xyz.exe, you can simply see it is started based on the tray icon, it doesn't actually execute the script, doesn't show the welcome screen or anything else. Only when the user presses ctrl+shift+p the script will be executed and welcome screen would be shown.

What I would like to achieve is when the user double clicks on xyz.exe, it should start the script (as if the user has pressed ctrl+shift+p) and show the welcome screen. Is there any way to achieve that?

Thanks.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to run script automatically when in exe form

10 Dec 2017, 23:41

If you're asking how to check if the script has been compiled into an executable, you can use the built-in A_IsCompiled variable. Near the top of your script (before your hotkeys, to be safe), add the following:

Code: Select all

If A_IsCompiled
{
  Goto ^+p
}
That should process the code under your Ctrl+Shift+P hotkey whenever anyone starts the script. I assume that that's what you're trying to do.
Last edited by Osprey on 11 Dec 2017, 01:10, edited 3 times in total.
ctrl+shift+a
Posts: 5
Joined: 10 Dec 2017, 22:45

Re: How to run script automatically when in exe form

10 Dec 2017, 23:49

Thanks Osprey, especially for such an immediate response. Actually, my logic is not dependent upon "A_IsCompiled", but probably I didn't explain my pain point very clearly ... I want my users to simply double click their xyz.exe and the code be called. I don't want them to have to double click the xyz.exe, wait for something to happen, then half of them possibly just give up thinking this thing doesn't work, while the other half may see the instructions that they have to now press ctrl+shift+p. I want the user's first experience such that they double click the xyz.exe and welcome screen shows - without they having to press the hot key (ctrl+shift+p).
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to run script automatically when in exe form

10 Dec 2017, 23:53

After posting, I re-read your post more carefully and edited my reply to give a more relevant suggestion. I didn't expect you to read it so quickly. Please see the edit and see if it's what you need.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: How to run script automatically when in exe form  Topic is solved

11 Dec 2017, 00:03

GoSub ^+p ? (Of note, Osprey used the Ctrl+Alt+p hotkey/label as Alt=!; if you really do mean Shift, it should be ^+p.)
ctrl+shift+a
Posts: 5
Joined: 10 Dec 2017, 22:45

Re: How to run script automatically when in exe form

11 Dec 2017, 00:09

Osprey, Exaskryz --- thanks a ton! I will try that later today and update the thread.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How to run script automatically when in exe form

11 Dec 2017, 01:12

Exaskryz wrote:GoSub ^+p ? (Of note, Osprey used the Ctrl+Alt+p hotkey/label as Alt=!; if you really do mean Shift, it should be ^+p.)
Thanks. Yes, I meant ^+p. It's late and I was in a hurry to edit that into my post before he saw it.
ctrl+shift+a
Posts: 5
Joined: 10 Dec 2017, 22:45

Re: How to run script automatically when in exe form

12 Dec 2017, 23:04

Osprey, Exaskryz ... thanks! This worked wonderfully. So far I hadn't realized that when you run the script, it will execute from the top to the first Label/Function/Sub???? I had always - mistakenly - thought that it is simply loaded in the memory and executed upon pressing the shortcut key.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: How to run script automatically when in exe form

12 Dec 2017, 23:20

Yeah, you can read more about that here: auto-execute section.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Google [Bot], inseption86, mikeyww and 425 guests