In 1 script: launch a program & execute a command Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
DutchPete
Posts: 75
Joined: 03 Feb 2015, 03:59

In 1 script: launch a program & execute a command

22 Jan 2018, 12:00

I am trying to write a script to do the above 2 things. So here is where I am at:

to launch a program this is the code
!x::
run, C:\Program Files (x86)\CherryTree\bin\cherrytree.exe

to collapse the hierarchy tree in that program this is the code
+^L (i.e. Shift+CTRL+L)

I am stuck on how to merge those lines of code in 1 script so that they are executed consecutively when the script is activated.
garry
Posts: 1205
Joined: 22 Dec 2013, 12:50

Re: In 1 script: launch a program & execute a command

22 Jan 2018, 17:22

example here for notepad
alt+x start once notepad and send text / otherwise just activate it and send text

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

A_AhkUser
Posts: 757
Joined: 06 Mar 2017, 16:18
Location: France

Re: In 1 script: launch a program & execute a command  Topic is solved

22 Jan 2018, 17:23

Hi,

Try the following:

Code: [Select all] [Download] GeSHi © Codebox Plus

!x::
run, C:\Program Files (x86)\CherryTree\bin\cherrytree.exe,,, OutputVarPID ; run the program and store its process ID in 'OutputVarPID'
WinWait, ahk_pid %OutputVarPID% ; wait for the first window belonging to the process to appear
WinActivate ; activate the window (actually, if all parameters are omitted, the 'last found' window - set by the WinWait command above - is used instead)
WinWaitActive ; same remark as above
sleep, 100
Send, {Shift Down}{Ctrl Down}l{Shift Up}{Ctrl Up}
return
DutchPete
Posts: 75
Joined: 03 Feb 2015, 03:59

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 00:41

Hi Garry, thanks for replying. I was not sure exactly what you meant, so I tried AhkUser's suggestion. That worked.
DutchPete
Posts: 75
Joined: 03 Feb 2015, 03:59

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 00:45

Hi AhkUser, thanks for helping out. Yes, your script works, so I am a happy bunny :), esp. because it is a workaround for a feature that is not working in the Windows version of Cherrytree, which is a good note-taking app.
I see your location is France, so I say: je vous remercie encore une fois, et peut-être à la prochaine. Salut !
garry
Posts: 1205
Joined: 22 Dec 2013, 12:50

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 08:40

I'm not sure if this works ( didn't tried the program cherrytree.exe )
just an idea , if use hotkey alt+x again , shouldn't start program cherrytree again
EDIT : modified used PID

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by garry on 23 Jan 2018, 09:04, edited 1 time in total.
DutchPete
Posts: 75
Joined: 03 Feb 2015, 03:59

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 08:55

garry wrote:I'm not sure if this works ( didn't tried the program cherrytree.exe )
just an idea , if use hotkey alt+x again , shouldn't start program cherrytree again

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



Garry, what does this code do? Right now I am able to launch CT and collapse its tree with just 1 keyboard combination.
garry
Posts: 1205
Joined: 22 Dec 2013, 12:50

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 09:02

I was thinking , the program starts again if use alt+x again
I modified script above

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


bent U van Nederland ?
http://jabod.studyit.nl/boudewijn/
DutchPete
Posts: 75
Joined: 03 Feb 2015, 03:59

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 09:15

Why would I use Alt+X again? I only use it once to launch a number of programs, incl. CT, and after that I stay away from Alt+X.
So what does your code do? I don't understand the calc.exe and the notepad.exe parts.

Ja, ik ben Nederlander. Waarvoor zijn de mp3 files in de link?
garry
Posts: 1205
Joined: 22 Dec 2013, 12:50

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 09:38

Why would I use Alt+X again? I only use it once to launch a number of programs, incl. CT, and after that I stay away from Alt+X.

just if accidentally pressed again ...

So what does your code do? I don't understand the calc.exe and the notepad.exe parts.

this was for test

Ja, ik ben Nederlander. Waarvoor zijn de mp3 files in de link?

oude muziek om te luisteren als je het alleen leuk vindt
(Ik ben oud ... maar ik denk dat je niet ...)
DutchPete
Posts: 75
Joined: 03 Feb 2015, 03:59

Re: In 1 script: launch a program & execute a command

23 Jan 2018, 11:33

Thanks Garry, but I would not press Alt+X again accidentally.
Dank voor de muziek, ik ben een klein beetje oud :-)

Return to “Ask For Help”

Who is online

Users browsing this forum: JoSc1965, Rohwedder, superfalse, swagfag and 36 guests