Detect if PhonerLite is running

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Detect if PhonerLite is running

13 Dec 2017, 11:43

Today I want to write a little script to toggle the PhonerLite window.
So I have this code attached to a hotkey.
Problem is that it doesn't fetch any pid, even though I can see in Task Manager that PhonerLite.exe is amoungst the processes running.
And I can see PhonerLite is minimized to the system tray.
AutoHotkey 1.1.26.01 Unicode on Windows 7 Pro x64

Code: Select all

PhonerLite(){
	process, exist, PhonerLite.exe
	msgbox, %thispid%
	thispid = %ErrorLevel%
	if(thispid){
		winactivate, %thispid%
	}else{
		run,  "C:\Program Files (x86)\Phoner\PhonerLite.exe"
	}
}
Is there something else to try?
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Detect if PhonerLite is running

13 Dec 2017, 11:57

Code: Select all

F10::MsgBox % PID := Process("PhonerLite.exe","C:\Program Files (x86)\Phoner") ; press F10

Process(application, appPath) {
	Process, Exist,% application
	PID := ErrorLevel
	If (PID){
		WinActivate,% "ahk_pid " . PID
	} Else {
		Run,% appPath . "\" . application
    }
    Return PID
}
Not tested.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect if PhonerLite is running

13 Dec 2017, 12:01

Process
https://autohotkey.com/docs/commands/Pr ... m#Examples

Code: Select all

; Example #5: Retrieves a list of running processes via COM.
Ah, as BoBo has worked out, it seems you missed out ahk_pid, so hard to spot these things!
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 12:08

oh, whoops - I put the messagebox on the wrong line - hahahahaha
Thanks for your help, guys; sorry for the noise. I stared at that for ten minutes and didn't see the problem.
Okay, now it fetches the pid, but winactivate doesn't pull the window up. Maybe the window doesn't exist unless I click the tray icon?

So I have this:
winactivate, % "ahk_pid " . pid

When I push the hotkey, whatever window I have active becomes inactive, though. So *something* is happening! But it doesn't bring the PhonerLite window from system tray.
In fact, even if PhonerLite has it's window open on the screen, it doesn't get activated, that is, the title bar doesn't become not gray - but it does receive keyboard commands.

I tried adding #WinActivateForce, but that doesn't seem to do as well as without it. Without it, at least there is keyboard focus; with it, there is nothing.
And, if it makes any difference, the script hosting this function also has:
settitlematchmode 2
detecthiddenwindows, on
Last edited by BGM on 13 Dec 2017, 12:23, edited 1 time in total.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Detect if PhonerLite is running

13 Dec 2017, 12:22

What about to use WinRestore instead?
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 12:27

WinRestore?
It's in the online docs for v1, and it's not in the ahk chm file. https://autohotkey.com/docs/commands/WinRestore.htm

Okay, so when I do *that* - haha - it opens a dropdown box in PhonerLite... strange.

All righty, so the pid belongs to the window for sure. I'll try activating it by title.

...nope - can't make the window active with anything.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect if PhonerLite is running

13 Dec 2017, 12:38

Yes, try the class or title, because sometimes the first window you find belonging to a PID, is not the main window.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 12:44

WinSpy tells me that the pid *IS* for the main window, though.

This doesn't work, either: controlclick, TMainForm, PhonerLite
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect if PhonerLite is running

13 Dec 2017, 12:50

All windows belonging to the same instance of a process, will have the same PID. E.g. Notepad's main window, and the Find dialog, will have the same PID. What are the class and title for PhonerLite's main window? Either one of those might be enough to uniquely identify the window, and you wouldn't even need to know the PID. You can also use ahk_exe to help uniquely identify the window.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 12:54

The main class is for PhonerLite is TMainForm and the title bar reads PhonerLite and there are no other windows that I know of that have that title.
But it doesn't activate the window, even if the window is right on the screen.

This doesn't work, either:
winactivate, ahk_exe C:\Program Files (x86)\Phoner\PhonerLite.exe
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect if PhonerLite is running

13 Dec 2017, 13:06

Some ideas:

Code: Select all

WinShow, ahk_class TMainForm ahk_exe PhonerLite.exe
WinActivate, ahk_class TMainForm ahk_exe PhonerLite.exe
WinGet, vCount, Count, ahk_class TMainForm ahk_exe PhonerLite.exe
MsgBox, % vCount
[EDIT:]

Code: Select all

;changed:
WinGet, vCount, List, ahk_class TMainForm ahk_exe PhonerLite.exe
;to:
WinGet, vCount, Count, ahk_class TMainForm ahk_exe PhonerLite.exe
;note: both work, but List creates additional variables (a pseudo-array)
Last edited by jeeswg on 14 Dec 2017, 14:46, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 13:10

Okay, *some* progress!
WinActivate, ahk_class TMainForm ahk_exe PhonerLite.exe
will show it then hide it. Then it doesn't work a second time.

Also, I think the title keeps changing depending on what is in the dropdown box (call history).
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 15:15

Phoner must have some self-check built into it to keep it minimized to the tray.

If I do this, then it brings the window from the system tray and displays it for a few seconds, then the window disappears again.

Code: Select all

WinShow, ahk_class TMainForm ahk_exe PhonerLite.exe
WinActivate, ahk_pid %thispid% ahk_exe PhonerLite.exe
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 15:21

Ah, okay, I figured out a solution.

I was running this in quotes. If I run it without quotes, then it just switches to the running application and brings it to the foreground - just like I wanted. I don't need any of the process or winactivate commands at all.
Strange gui.

Code: Select all

run,  C:\Program Files (x86)\Phoner\PhonerLite.exe
Thanks for your help, jeeswg.
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: Detect if PhonerLite is running

13 Dec 2017, 15:31

Here is the final script, if anyone is interested:

Code: Select all

phonerlite(){
	phonerliteapp := "C:\Program Files (x86)\Phoner\PhonerLite.exe"
	process, exist, PhonerLite.exe
	thispid := errorlevel
	if(thispid){
		;if PhonerLite window is open on the screen, then minimize it
		wingettitle, thistitle, ahk_pid %thispid%
		if(thistitle){
			winminimize, ahk_pid %thispid%
		}else{
			;if PhonerLite is minimized, then bring it to the front
			run,  %phonerliteapp%
		}
	;if it isn't running, then start the program		
	}else{
		run, %phonerliteapp%
	}
	return thispid
}
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Detect if PhonerLite is running

13 Dec 2017, 15:45

- Omg, yes, just run the exe, sometimes the simplest solutions are the best, that was the answer for me oftentimes for most programs, when tray icons disappeared. I.e. before I used AutoHotkey, I'd click the Start menu icon again.
- I would imagine that by using the tray icons library, you could retrieve the hWnd of the window that receives notifications for the tray icons. You could find out the unique identifying information about that window, e.g. its class. You could then send a message to invoke a mouse click, which would have the same effect as clicking the icon manually.
Link: [LIB] TrayIcon - Sean's TrayIcon for Unicode and 64 bit - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=1229
- I also wrote a script that can handle tray icons.
Link: GUIs via DllCall: get/set internal/external control text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40514
- You could try getting a list of menu item IDs when hovering over the systray menu items.
Link: Get Info from Context Menu (x64/x32 compatible) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=31971
- With some programs you can try running that program again with a command line option and will affect the currently running instance.
- [EDIT:] I'll do a post on tray icon interaction, in perhaps the next the week.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: imstupidpleshelp, marypoppins_1, sbrady19 and 161 guests