How do you delay the launch of a program when executed?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bartholomew
Posts: 21
Joined: 17 Feb 2017, 16:33

How do you delay the launch of a program when executed?

18 Mar 2017, 07:13

Hello everyone,

Does anybody know how to delay the launch of a program once it has been executed?

For example, I double click on a PDF file, the PDF file wants to launch immediately the Adobe Acrobat Reader's .exe file to launch Adobe and open the PDF. I want a delay. I want Adobe's .exe file to delay for a second or so and have another program open first then allow the the Adobe .exe to finish opening and of course finish loading the PDF.

This kind of script can help me a lot and save me a lot of headaches. I would be most grateful for such a script.
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: How do you delay the launch of a program when executed?

18 Mar 2017, 07:41

You could make a script to launch the first program, then sleep and then run adobe to open the PDF. On your computer if set your script to be the default program for opening PDFs it should work. You may need to compile it for that work, I don't know, but it does make it a lot simpler if you do.

Just pseudo code but something along the lines of:

Code: Select all

If 0 <> 1 ; Command line variables are just numbers, which doesn't play well with expressions.
    ExitApp ; If there isn't a command-line argument just exit.

PDF = %1% ; Command line variables are just numbers, which doesn't play well with expressions.

Run, Your first program
Sleep 5000 ; wait 5 seconds
Run, Adobe.exe %PDF%
ExitApp
I've never done this or tested it, but I don't see why it wouldn't work. You will probably lose the pdf icon though, maybe if you change the icon of your program it will use that, not sure. You may also add checking to make sure the file is actually a PDF before launching adobe
Bartholomew
Posts: 21
Joined: 17 Feb 2017, 16:33

Re: How do you delay the launch of a program when executed?

24 Mar 2017, 17:32

Hello everyone,

I thought to paste the solution. Nightwolf85 provided the following script to me.

I was able to modify it to give me the results I needed. Essentially, this script as it is, is what I needed.






#SingleInstance Force
SetTitleMatchMode, 2

If 0 <> 1 ; Command line variables are just numbers, which doesn't play well with expressions.
ExitApp ; If there isn't a command-line argument just exit.

File = %1% ; Command line variables are just numbers, which doesn't play well with expressions.

IF (RegExMatch(File, "^.*\.xls.*$")) {
RegRead, usePath, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe
FileType := "excel"
}
Else IF (RegExMatch(File, "^.*\.doc.*$")) {
RegRead, usePath, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Winword.exe
FileType := "Word"
}
Else IF (RegExMatch(File, "^.*\.ppt.*$")) {
RegRead, usePath, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\powerpnt.exe
FileType := "PowerPoint"
}
Else
ExitApp ; File isn't a type we handle


IF (FileType = "excel") {
Run, % usePath ; Change this to the pre-excel program's Path.
WinWait, Excel,,,Opening
}
Else IF (FileType = "Word") {
Run, % usePath ; Change this to the pre-Word program's Path.
WinWait, Word,,,Opening
}
Else IF (FileType = "PowerPoint") {
Run, % usePath ; Change this to the pre-PowerPoint program's Path.
WinWait, PowerPoint,,,Opening
}

Run, % usePath . " """ . File . """"
ExitApp

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: alawsareps, mebelantikjaya, mikeyww, RussF and 312 guests