Open or Focus XY from Desktop

Discuss and share scripts and script files...
Post Reply
VeeGee

Open or Focus XY from Desktop

Post by VeeGee »

Good afternoon all,
Other file managers have an option to load or focus their app by double-clicking an empty spot on the desktop. I checked XY settings and didn't find any such option or ability. Now, this isn't an option I even thought I would use, but I actually tried it out and found it useful (in some situations).

My XY is set as this :
Configuration | General | Startup & Exit | [ ] Allow multiple instances (unchecked)

This is super quick and dirty but is working. I was also experimenting with detecting if the XY process is already running and switch to it but XY is pretty smart and does that on the run command anyway. No idea how this runs when multiple instances are enabled.

The AutoHotkey script I cobbled together is here, link inside to where I got most of the code from :

Code: Select all

; https://www.autohotkey.com/board/topic/82196-solved-double-click-on-the-desktop/

; ahk_class ThunderRT6FormDC
; ahk_exe XYplorer.exe
; XY_Process = XYplorer.exe

~LButton::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500) {
	WinGetClass, Class, A
	if (Class = "WorkerW") or (Class = "Progman") {
		if (_EmptyDesktopSpot()) {
			run, C:\Program Files (x86)\XYplorer\XYplorer.exe
		}
	}
}
return

_EmptyDesktopSpot() {
	LVM_GETSELECTEDCOUNT := 0x1000 + 50
	GroupAdd, DeskGroup, ahk_class WorkerW
	GroupAdd, DeskGroup, ahk_class Progman
	handle := WinExist("ahk_group DeskGroup")

	if (! handle) {
		return false
	}

	handle := DllCall("GetWindow","Ptr",handle,"Uint",5,"Ptr")
	if (! handle) {
		return false
	}

	handle := DllCall("GetWindow","Ptr",handle,"Uint",5,"Ptr")
	if (! handle) {
		return false
	}

	SendMessage,%LVM_GETSELECTEDCOUNT%,0,0,,ahk_id %handle%
	if (ErrorLevel = "FAIL") {
		return false
	}

	if (! ErrorLevel) {
		return true
	}

	return false
}
I also compiled this to EXE, here is a sample compile CMD file :

Code: Select all

"C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.exe" /in "C:\Data\Projects\XYScripts\XYOpenFromDesktop\XYOpenFromDesktop.ahk" /out "C:\Data\Projects\XYScripts\XYOpenFromDesktop\XYOpenFromDesktop.exe" /icon "C:\Data\Projects\XYScripts\XYOpenFromDesktop\XYOpenFromDesktop.ico"
Hopefully someone else can find this useful and even expand on it and share back, e.g. better implementation, error trapping, etc.
Maybe a future XY release can add this option already, again, apologize if it's already there, I couldn't find it.

GreetingsFromPoland
Posts: 213
Joined: 29 Sep 2022 14:20

Re: Open or Focus XY from Desktop

Post by GreetingsFromPoland »

this is good. thank you for your posting. the script works well. i did make a few changes as my software is installed in a different location. i use RegRead to locate the EXE and run from that location. i also make different tooltip display.

developer, is this a feature that you could add to the functionality of the XY software ? it is an option in other file managers and may be useful to others, either built-in or as an extra compiled AHK program.

my changes :

Code: Select all

Menu, Tray, Tip, XYOpenFromDesktop
RegRead, XYEXE, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\XYplorer.exe

Code: Select all

if (_EmptyDesktopSpot()) {
	if FileExist(%XYEXE%) {
		run, %XYEXE%
	}
}

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

This is quite handy. I use the same double-click AHK lines for some other actions, but it works great for running, or in most cases, activating XYplorer from the desktop. I incorporated it into my AHK startup script. :tup:
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Horst
Posts: 1080
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Open or Focus XY from Desktop

Post by Horst »

I use a similar AHK script but not by Double clicking on the Desktop as it is not always seen.
I made it by double clicking on an empty space on the taskbar.
Windows 11 Home x64 Version 23H2 (OS Build 22631.3235)
Portable XYplorer (actual version, including betas)
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

Hi Horst, could you post your code lines for double-clicking on the taskbar? I'm sure I can find it on the AHK forum but if you have them handy. As you said, sometimes the desktop is not readily available, so the taskbar is also a good option. Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Horst
Posts: 1080
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Open or Focus XY from Desktop

Post by Horst »

Here my version, which starts the Pop-up of QAP

Code: Select all

; Double click in taskbar

~LButton::
   If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500)
   {
      WinGetClass, Class, A
      If ( Class = "Shell_TrayWnd" )
         run, C:\Tools\QuickAccessPopup\QAPmessenger.exe ShowMenuLaunch
   }
Return
Windows 11 Home x64 Version 23H2 (OS Build 22631.3235)
Portable XYplorer (actual version, including betas)
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

Thanks Horst. Since I have XY on my taskbar so I'm not sure how much I'll use it or need it...we'll see. :tup:
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

Hi VeeGee, it looks like 4 lines that start with handle := DllCall("Get... are repeated. Probably just a cut and paste problem. Thanks.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

GreetingsFromPoland
Posts: 213
Joined: 29 Sep 2022 14:20

Re: Open or Focus XY from Desktop

Post by GreetingsFromPoland »

good catch klownboy.

i update my script also and it works. i also add Horst addition as an option because sometimes my mouse if far on the right of the taskbar and my pinned software icon is on the left. now i have both options.

maybe developer can build this into the software. i don't see why not.

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

I tweaked the AHK script to separate actions for the taskbar double-click and the desktop double-click. Also, distinguished between XYplorer currently running but not active and XY not running. This allows the user to provide different scripts or User CIDs to run when XYplorer starts or becomes active, dependent on where the clicking takes place. Of course, you don't have to run a script or CID when XYplorer starts, but this gives you examples of doing that if you like. See the script comments. You'll have to change the CIDs or scripts to your liking.

Code: Select all

~LButton::
If (A_PriorHotKey = A_ThisHotKey and A_TimeSincePriorHotkey < 500) {
   WinGetClass, Class, A
   if (Class = "WorkerW") or (Class = "Progman") {
      if (_EmptyDesktopSpot()) {
         If ( HWND := WinExist("ahk_class ThunderRT6FormDC") )
         {
         WinActivate, ahk_class ThunderRT6FormDC
         WinGetTitle, Title, A
         SendInput ^{Numpad1}  ;runs a menu in XY assigned to NumPad1
         TrayTip, , Running %TITLE% from Desktop,1
         return
         }
         else
         {
         Run, D:\Tools\XYplorer\XYplorer.exe /script=::#1405, D:\Tools\XYplorer ,,PID  ;starts XY with photo gallery (my CID)
         TrayTip, , Running XY from Desktop (PID %PID%),1
         return
         }
      }
   }
   If ( Class = "Shell_TrayWnd" ) {
      If ( HWND := WinExist("ahk_class ThunderRT6FormDC") )
      {
         WinActivate, ahk_class ThunderRT6FormDC
         WinGetTitle, Title, A
         SendInput ^{Numpad1}
         TrayTip, , Running %TITLE% from Tray (PID %PID%),1
         return
      }
      else
      {
         Run, D:\Tools\XYplorer\XYplorer.exe /script=::#1442, D:\Tools\XYplorer ,,PID  ;starts XY with SessionManager (my CID)
         TrayTip, , Running XY from Tray (PID %PID%),1
         return
      }
   }
}
return

_EmptyDesktopSpot() {
   LVM_GETSELECTEDCOUNT := 0x1000 + 50
   GroupAdd, DeskGroup, ahk_class WorkerW
   GroupAdd, DeskGroup, ahk_class Progman
   handle := WinExist("ahk_group DeskGroup")
   if (! handle) {
      return false
   }
   handle := DllCall("GetWindow","Ptr",handle,"Uint",5,"Ptr")
   if (! handle) {
      return false
   }
   SendMessage,%LVM_GETSELECTEDCOUNT%,0,0,,ahk_id %handle%
   if (ErrorLevel = "FAIL") {
      return false
   }
   if (! ErrorLevel) {
      return true
   }
   return false
}
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Horst
Posts: 1080
Joined: 24 Jan 2021 12:27
Location: Germany

Re: Open or Focus XY from Desktop

Post by Horst »

Nice script, added to my examples :)
Windows 11 Home x64 Version 23H2 (OS Build 22631.3235)
Portable XYplorer (actual version, including betas)
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

Thanks Horst, if you think of any other options to add let me know.

Having the AHK script run a CID or script along with starting or activating XY is actually worthwhile (i.e., if XY is already running and active, it will simply run the CID (e.g., a menu - the menu simply pops up on the already active XYplorer).
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

GreetingsFromPoland
Posts: 213
Joined: 29 Sep 2022 14:20

Re: Open or Focus XY from Desktop

Post by GreetingsFromPoland »

this is all very nice. i am able to add parts to version that work for me.

i did notice one problem, i had to remove the % from the variable on this line as i was getting "illegal character..." from FileExists :

Code: Select all

if FileExist(XYEXE) {

klownboy
Posts: 4089
Joined: 28 Feb 2012 19:27

Re: Open or Focus XY from Desktop

Post by klownboy »

GreetingsFromPoland wrote: 20 Nov 2022 17:15

Code: Select all

if FileExist(XYEXE) {
I'm not sure why you bother using RegRead. When you know where XYplorer is located just specify the path and filename, why read the registry every time to determine its location? For users with a portable installation that wouldn't work anyway. :)
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

GreetingsFromPoland
Posts: 213
Joined: 29 Sep 2022 14:20

Re: Open or Focus XY from Desktop

Post by GreetingsFromPoland »

i only use to learn more about the AHK language and how it works. since i used them and they worked, i can now remark out those lines (for regread and fileexist) and use hardpath location.

Post Reply