Multiple ahk-based jump lists; text files as parameter vehicles

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GosHotk
Posts: 7
Joined: 11 Jun 2021, 12:57

Multiple ahk-based jump lists; text files as parameter vehicles

Post by GosHotk » 16 Jun 2021, 17:22

I've just switched from Win7 to Win10, and was looking for a way to both open an Explorer window to a particular folder and position the window in terms of left/top/width/height. Windows veterans may know that that was a built-in feature of WinXP (individual folders remembered their last screen positions). And it wasn't built in to Win7, but there was a freeware program (ShellFolderFix) that ran in the background and performed the same function very nicely. But alas, ShellFolderFix apparently doesn't work reliably in Win10, leading to my search for a replacement.

I'm also brand new to both PowerShell and AutoHotkey (although I've done quite a bit of coding in other languages), but I ended up Googling my way to functional scripts in both. Both scripts are a bit clumsy in that the folder first shows on the screen in its Win-default place (i.e., matching the last Explorer window that was closed), then disappears, then reappears in the script-assigned place. But that opening stutter is a considerably-faster blink in AutoHotkey than it is in PowerShell (in my scripts anyway).

I'm also new to jump lists (didn't use them in Win7), but was looking into the possibility of having an AutoHotkey taskbar icon with a jump list of positioned folders. And my initial inclination was to have the five values for each jump list item (folder path, left, top, width, height) be parameters in that item's "target" (not what it's called, I know). But it looks like jump list items can't include multiple parameters. A jump list item consists of just a single parameter (in effect) that gets passed to the pinned program.

There are various ways around that limitation in this case, though, and I'm posting my current approach on the chance that one or more of its aspects may be of interest to one or more readers.

For starters, the general rule (as I understand it) is that there can only be one pinned taskbar icon per program. But it turns out that if you compile an AutoHotkey script under two or more different names, each of those .exe files is a different program as far as Win10 is concerned — so you can have as many pinned AutoHotkey scripts on your taskbar as you like (assuming you compile them), each with its own jump list, and two or more of those pinned scripts can be duplicate copies of the same script (with different jump lists).

Secondly, and although I initially thought I might have to visit the Registry and associate a file type with one of those pinned programs to be able to add files (with that extension) to its jump list, it turns out Win10 is very flexible in that regard, at least if you're dealing with a pinned program that doesn't have associated extensions. It seems to insist that a jump-list-entry file have some extension (and it shows the extension on the jump list menu), but I've found that I can feed a pinned AutoHotkey .exe a text file with virtually any extension. So, for example, a text file that results in a positioned Explorer window opening to the C:\Playlists folder could be named Playlists._ (rather than, e.g., Playlists.txt), and in that case Playlists._ is what will appear on the jump list menu.

Which leads me to the third aspect of my current approach — namely, that you can use a text file to feed an AutoHotkey script (compiled or uncompiled) as many parameters as you want, not to mention multiple sets of parameters (so the same jump list entry could open multiple positioned explorer windows).

Here's my script as of today:

Code: Select all

if A_Args.Length() = 0 {
	ShowWindow("C:\", 600, 300, 450, 700)
	Exit
}

Loop, read, % A_Args[1]
{
	Loop, parse, A_LoopReadLine, `,
	{
		switch A_Index
		{
		case 1:
			Path := A_LoopField
		case 2:
			Left := A_LoopField
		case 3:
			Top := A_LoopField
		case 4:
			Width := A_LoopField
		case 5:
			Height := A_LoopField
		}
	}
	
	ShowWindow(Path, Left, Top, Width, Height)
	}
}

ShowWindow(Path, Left, Top, Width, Height) {

Path := Trim(Path, """")
Path := StrReplace(Path, "\\", "\")

switch InStr(Path, "\")
{
case 0, StrLen(Path):
	switch
	{
	case InStr(Path, "C:", false):
		FolderName := "OS (C:)"
	case InStr(Path, "D:", false):
		FolderName := "DATA (D:)"
	case InStr(Path, "20D04FE0", false):
		FolderName := "This PC"
	}
default:
	SplitPath, Path, FolderName
	if !(InStr(FileExist(Path), "D")) {
		MsgBox % Path " is not a folder." "`r`n`r`n" "Aborting..."
		Exit
	}
}

RunWait, explorer %Path%
sleep, 500
WinMove, %FolderName%,, Left, Top, Width, Height
return
}
I should mention that the window-positioning lines came from https://www.autohotkey.com/boards/viewtopic.php?t=60842, so h/t to all appropriate sources.

As for the rest of the lines... I already confessed to my n00b status, and I'd welcome any criticisms and/or tuneups that anyone wants to suggest.

Here's a sample text file (named C & D._) that can be used as a jump list item for a compiled copy of that script that's pinned to the taskbar, and that will open two Explorer windows next to each other, one to C:\ and one to D:\:

Code: Select all

"C:\\", 500, 300, 450, 700
D:\, 1000, 300, 450, 700
The difference between "C:\\" and D:\ is just there for demo purposes. I wrote the script with the intent to make it flexible/forgiving with drive reference variations like C: or C:\ or "C:" or "C:\" or "C:\\".

I should also note that you're free to change the taskbar icons for pinned programs. Compiled AutoHotkey scripts start out with the AutoHotkey icon, but after pinning one to the taskbar, you can Shift-right-click and go to Properties and change the icon. (The change doesn't take effect immediately, but it shows up after a few minutes without the need to restart.)

EDITED TO ADD: I have just learned that you can choose your own icon (for the .exe file) for compiled ahk scripts if you use the ahk2exe utility to do the compiling. The corresponding .exe file's icon is the one that will inevitably (I think) show up next to each item in a jump list, so you may want to use an invisible icon (nothing but transparent) for a script that you're compiling to use as a jump list base, to keep the distracting column of (identical) icons out of the jump list -- and again, you can choose a different icon to be the one in the taskbar.

And probably needless to say, you can use this technique to create as many custom jump lists as you like, and the items in the lists can involve anything an AutoHotkey script (or other program called by an AutoHotkey script) can do. As one example of some additional flexibility, in place of the ShowWindow call in my main script, I could substitute these lines:

Code: Select all

	if (Path = "RunAhk") {
		RunWait, AutoHotkey.exe %Left%
	} else {
		ShowWindow(Path, Left, Top, Width, Height)
	}
And then the jump list for the resulting pinned .exe could include this text file:

Code: Select all

RunAhk, C:\Bin\AH\SomeOtherScript.ahk
C:\Playlists, 800, 100, 400, 600
And the result of clicking on that jump list entry would be that SomeOtherScript would run, and then the C:\Playlists folder would open in an Explorer window in the designated place.

As a final (very tangential) note... I'm a longtime user of taskbar toolbars, and may end up deciding I'd rather stick with those (pointing now to AutoHotkey shortcuts) as my preferred vehicle for opening positioned Explorer windows in Win10. For anyone unfamiliar with them, taskbar toolbars are a longtime built-in Windows feature that lets you create a folder of shortcuts — and/or of subfolders of shortcuts (and/or of sub-subfolders of shortcuts, and so on down as many levels as you like) — and then shrink the width of the toolbar (on the taskbar) to a single icon (or two, or three), in which case (assuming the folder has more items) there will also be a little double-arrow next to the icons that are shown, and clicking on that will give you a flyup menu of the other items in the folder. And if any of those items are folders with more shortcuts, hovering over them gets you a flyout menu of those to the left or right. All the shortcut lists that display above the taskbar show the icon and name both, but you can choose to have the items that show in the taskbar be icon-only. So you can end up with a narrow icon-and-arrow combo in the task bar that leads to a many-foldered tree of shortcuts. It's long been one of my favorite components of what you might call the Windows "dashboard," and it looks like it's survived into Win10 unscathed.

EDITED TO ADD (re taskbar toolbars): I should also have mentioned that for taskbar display purposes, the shortcuts in a taskbar toolbar can be ordered any way you want (by clicking and dragging), rather than having to be sorted in one way or other. This applies to both the item that shows (or items that show) in the taskbar and the ones in the flyup.

Return to “Ask for Help (v1)”