Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Automating Windows Explorer


  • Please log in to reply
39 replies to this topic
MisterW
  • Members
  • 65 posts
  • Last active: Jun 18 2007 11:14 AM
  • Joined: 20 Jul 2005
Does anyone know shortcuts for doing any of the following? (not by automating mouse movement/clicks or keypresses - I'll revert to that if I have to...)

1. Create a new Folder in explorer

Currently using:

Send {AppsKey}wf{Enter}{F2}

I checked the list of shortcut keys on the forum and F7 doesn't seem to work.

2. Switch the view style between (for instance) Icon format and detail format.

3. Launch Explorer opening it at "My Computer"

Tried these kind of options from Microsoft's Knowledge base but can't get them to work for "My Computer"

Explorer /root /e /root /select etc...

I don't want a treeview but rather as if you double clicked on My Computer icon on desktop (single pane).

Ok. Found it:

explorer.exe ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}

this came from a pcworld article.

4. Toggle Hidden folders/files on or off

5. Change sort ordering/type in explorer eg by date/size etc

6. Toggle Mouse activating Windows by hovering over them.

tried setting the appropriate option in the registry but it didn't update immediately like it does when using TweakUi.

Some programs menus don't behave very well with this setting enabled

7. Launch a file using an alternative action eg "edit script"

eg ctrl double click to edit a file/script rather than run it. My context menu is a little slow and can get a bit cluttered - even after cleaning a heap of useless stuff from it


Basically I want to assign hotkeys to (toggle) these actions if possible. Looking for the appropriate shortcut keys, registry entries, postmessage/sendmessage codes, etc... to perform any of these behaviours

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Sorry for the delayed response.

I think I know solutions for a few of these. If you still need them, please post again.

MisterW
  • Members
  • 65 posts
  • Last active: Jun 18 2007 11:14 AM
  • Joined: 20 Jul 2005

I think I know solutions for a few of these. If you still need them, please post again.


Hi Chris, I'm still interested so anything that you have would be useful. I'm a little surprised there isn't more demand for these things...

not-logged-in-daonlyfreez
  • Guests
  • Last active:
  • Joined: --
There have been numerous attempts to control Explorer in the Forum, and it comes down to the problem how to let the system know changes have occurred, how to do a 'refresh'...

Babis
  • Members
  • 69 posts
  • Last active: Aug 26 2015 09:31 AM
  • Joined: 08 Dec 2005

2. Switch the view style between (for instance) Icon format and detail format.

icon= ALT, V, N
detail= ALT, V, D

5. Change sort ordering/type in explorer eg by date/size etc

sort by date: ALT, V, I, M
sort by size: ALT, V, I, S

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

1. Create a new Folder in explorer

This one is of high interest to me and other people, but seems difficult to do with 100% reliability and in a way that works on all languages. I think Tekl or someone else had an alternate way to do it, perhaps involving FileCreateDir and then having the script wait for the folder to appear. But I'm still on the lookout for a more seamless way to do it (I'm currently using Send !fwf).

2. Switch the view style between (for instance) Icon format and detail format.

(Assuming sending keystrokes isn't satisfactory): Although I haven't tried it with Explorer, you could try sending the message LVM_SETVIEW or LVM_SETEXTENDEDLISTVIEWSTYLE, which are described at MSDN: http://msdn.microsof... ... etview.asp

6. Toggle Mouse activating Windows by hovering over them.

"Activation follows mouse". I think there's a way to dynamically turn on and off the activation setting, perhaps via DllCall and SystemParametersInfo(), but I forget the details.

7. Launch a file using an alternative action eg "edit script"

Run and RunWait support some of the standard verbs like "edit" and "print". For example: Run edit "C:\My Text File.txt"

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005

1. Create a new Folder in explorer

This one is of high interest to me and other people, but seems difficult to do with 100% reliability and in a way that works on all languages. I think Tekl or someone else had an alternate way to do it, perhaps involving FileCreateDir and then having the script wait for the folder to appear. But I'm still on the lookout for a more seamless way to do it (I'm currently using Send !fwf).

!fwf is indeed specific to English... For me, it would be !fn{Enter} or even !fn{Enter}{Enter} if there is already files selected.

Well, the nice thing with AHK is that you don't necessarily need to write the scripts for all systems, but you can tweak them to fit your specific needs. Unless, of course, you manage hundred of heterogenous computers...

The case of creating a new folder in the current view of Explorer has been solved in a way that seems quite system agnostic, as long as the option to display the full path in the title bar is activated.

7. Launch a file using an alternative action eg "edit script"

Run and RunWait support some of the standard verbs like "edit" and "print". For example: Run edit "C:\My Text File.txt"

The difficult part here is to get the name of the selected file, I think.
One can do it like this:
	appName = Test AHK
	WinGetClass winClass, A
	If winClass != ExploreWClass
	{
		MsgBox 16, %appName%, Oops, wrong window...
		return
	}
	WinGetActiveTitle currentPath
	Send {F2}^C{Esc}
	MsgBox 64, %appName%, %currentPath%\%Clipboard%
at the expense of loosing the clipboard content.
I tried to get the item name using SendMessage (first try at this command...), but I have no success. If somebody can explain what is wrong in the code below... (Edit: perhaps I found it, it is harder than it seems, as Windows may not allow to get data from another process.)
	LVM_FIRST = 0x1000
	LVM_GETSELECTIONMARK := LVM_FIRST + 66
	LVM_GETITEMTEXT := LVM_FIRST + 45
	LVIF_TEXT = 0x1
	; SendMessage LVM_GETSELECTIONMARK, 0, 0, FolderView, A
	SendMessage LVM_GETSELECTIONMARK, 0, 0, SysListView321, A
	itemIndex = %ErrorLevel%
	VarSetCapacity(item, 13*4, 0)
	VarSetCapacity(fileName, 257, 0)
	InsertInteger(LVIF_TEXT, item, 0)	; mask
	InsertInteger(11, item, 1*4)	; iItem
	InsertInteger(0, item, 2*4)	; iSubItem
	InsertInteger(&fileName, item, 5*4)	; pszText
	InsertInteger(256, item, 6*4)	; cchTextMax
;	MsgBox % StructureDump(item, 13)
	SendMessage LVM_GETITEMTEXT, %itemIndex%, &item, SysListView321, A
	MsgBox %ErrorLevel% - %fileName%
I made a StructureDump function to better check what I put in the buffer:
StructureDump(ByRef pSource, pSourceSize = 1)
{
	intSize = 4
	old_FormatInteger := A_FormatInteger
	SetFormat Integer, hex
	result = Dump:
	Loop %pSourceSize%
	{
		intVal = 0
		offset := (A_Index-1) * intSize
		Loop %intSize%
		{
			intVal += *(&pSource + offset + A_Index-1) << 8 * (A_Index-1)
		}
		result = %result% %intVal%
	}
	SetFormat Integer, %old_FormatInteger%
	return result
}
I added it to the file with ExtractInteger / InsertInteger...
I could have used ExtractInteger here, but I prefer to make it standalone (faster?).

BTW, why these useful functions are not built in AHK, since they are complementary of DllCall/SendMessage?

shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005

1. Create a new Folder in explorer

This one is of high interest to me and other people, but seems difficult to do with 100% reliability and in a way that works on all languages. I think Tekl or someone else had an alternate way to do it, perhaps involving FileCreateDir and then having the script wait for the folder to appear. But I'm still on the lookout for a more seamless way to do it (I'm currently using Send !fwf).


If the concern is to ensure the view is automatically refreshed, then try:

note: available with Windows 2000+

FileCreateDir, d:\olly1

AnsiToUnicode( "d:\olly2", my_path )
result := DllCall( "shell32.dll\SHCreateDirectory", "uint", 0, "str", my_path )
return

AnsiToUnicode( p_text, byref r_text )
{
	StringLen, len, p_text
	
	VarSetCapacity( r_text, len*2+2 )

	success := DllCall( "MultiByteToWideChar"
							, "uint", 0			; CP_ACP
							, "uint", 1			; MB_PRECOMPOSED
							, "str", p_text
							, "int", len
							, "uint", &r_text
							, "int", len*2+2 )
	return, ! ErrorLevel or success
}

There is a better method using COM, which is available on all platforms from Windows 95 and later.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004

The difficult part here is to get the name of the selected file [in Explorer]

You can also use the following to avoid using the clipboard:
ControlGet, SelectedItem, List, Selected Col1, SysListView321, A
Also, to get the full path of a file in Explorer (avoiding the need to fetch Explorer's title bar text), you can do something like:
clipboard =
Send, ^c
ClipWait, 2
Sort, clipboard  ; This also converts to text (full path and name of each file).

If the concern is to ensure the view is automatically refreshed, then try:

Very nice. I'll probably put it to use.

The overall goal is to create a hotkey that exactly reproduces the behavior of choosing File > New > Folder from Explorer's menu bar (others have tried finding a message to send via SendMessage, without success). The only missing piece now is finding out Explorer's working directory, which is often solved by turning on the "show full path in title bar" option. There is probably a better way -- perhaps by querying Explorer's process attributes somehow.

Thanks.

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004

The only missing piece now is finding out Explorer's working directory, which is often solved by turning on the "show full path in title bar" option.


I prefer using the address bar to obtain the path from Explorer, it has the advantage of working with ControlGetText even if it's hidden:

wingetclass, class, A
if class not in CabinetWClass,ExploreWClass
  return

controlgettext, currentpath, Edit1, ahk_class %class%
msgbox, %currentpath%

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

  • Guests
  • Last active:
  • Joined: --

1. Create a new Folder in explorer


A couple of options:

#c::
wingetclass, class, A 
if class not in CabinetWClass,ExploreWClass 
  return 

controlgettext, currentpath, Edit1, ahk_class %class% 
i:=1
Loop
{
	ifExist, %currentpath%/NewFolder%i% 
		i:=i+1
	else {
		FileCreateDir, %currentpath%/NewFolder%i%
		break
	}
	
}
Send {F5}
return

#x::
wingetclass, class, A 
if class not in CabinetWClass,ExploreWClass 
  return 

controlgettext, currentpath, Edit1, ahk_class %class% 

InputBox, UserInput, New folder, New folder name, , 130, 130,,,,,NewFolder
if ErrorLevel = 0
{
	ifExist, %currentpath%/%UserInput% 
	 	FileCreateDir, %currentpath%/%UserInput%_1
	else
	 	FileCreateDir, %currentpath%/%UserInput%
}
Send {F5}
return
Also you can mix 1 and 2 to check if folder exists...

Me
  • Guests
  • Last active:
  • Joined: --

...
7. Launch a file using an alternative action eg "edit script"

While you're at it, how about

8. Switch between showing and hiding file extentions

Showing them is good for security reasons (amongst other things), temporarily hiding them is nice while renaming files.

Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004

2. Switch the view style between (for instance) Icon format and detail format.


You can use PostMessage:

1::PostMessage, 0x111, 28713,,, ahk_class ExploreWClass ; Large Icons
2::PostMessage, 0x111, 28714,,, ahk_class ExploreWClass ; Small Icons
3::PostMessage, 0x111, 28715,,, ahk_class ExploreWClass ; List
4::PostMessage, 0x111, 28716,,, ahk_class ExploreWClass ; Details

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

MisterW
  • Members
  • 65 posts
  • Last active: Jun 18 2007 11:14 AM
  • Joined: 20 Jul 2005
This doesn't do anything at all on my system. Am I supposed to add some refresh code to make this work?

evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005
In WindowsXP SP2 I'm getting 1 and 2 both displaying what corresponds to the "Icons" mode (not Tile), 3 and 4 work ok.

Also, is there one for Thumbnails? I'll see if I can find it myself if I have time and can figure out the method ok.