Toggle Hidden Files
My method is much more clean, and is much simpler. If the code is longer, it's only because my script offers to toggle the Show Hidden Files AND Show System Files independently, and most of the code is needed only for the tray menu and the command line arguments. In fact, the method is entirely contained in the two functions ShowHiddenFiles(mode) and RefreshExplorerWindows(). Approximately 20 lines of code. The rest is pure cosmetics, that you can easily remove if you just want to change the Hidden Files mode with a hotkey.
Hum, I don't like the methods that open a window to manipulate it.
Point taken, but I don't like directly manipulating the Registry. A mistake doing that can botch up the whole system.
I don't think there is much risk in sending keys to the folder options dialog.It's dangerous
subject to change from OS to OS
The Registry is also subject to change from OS to OS
Well, that's a matter of opinion. I prefer the simplest solution that works for the task at hand.and inelegant.
That's theoretically right but only when you manipulate critical parts of the registry, such as HKLM. It's not the case here.Point taken, but I don't like directly manipulating the Registry. A mistake doing that can botch up the whole system.
Again, theoretically right, but your script doesn't send the key to the option dialog. It opens it, then send the key. Although it may work fine 999 times/1000, it is not impossible that another window opens just when the key is sent, and that new window will receive it instead ot the option dialog. Sending keys blindly is always dangerous. My script uses ControlSend, so there is no risk to sent the key to another window.I don't think there is much risk in sending keys to the folder options dialog.It's dangerous
Right, but your script uses the registry too.subject to change from OS to OS
The Registry is also subject to change from OS to OS
IMO, the simplest solution is mine. Writing the correct value to the registry is direct, and it will work regardless of the system load and minor GUI changes. Your script is actually using the GUI to write the same value to the registry. One additional step, useless and prone to various problems. Also, I think that opening a window or popup menu just to send it a key doesn't look professional, and in that sense, it's inelegant.Well, that's a matter of opinion. I prefer the simplest solution that works for the task at hand.and inelegant.
Thanks! :-)Thank you r0lZ. You made wonderful script! Works correct on Win7 x64 with Autohotkey_L x64
1. I mapped Windows key + h as my toggle key combo, but you can use just about any other key combo you wish
2. I've noticed that it helps if your key combo choice is as-of-yet unused in the respective program
3. In this case WIN+h already activates the Windows "Share charm" but I rarely use it anyway
#h:: WinGetActiveTitle, WinTitle WinGetClass, WinClass, %WinTitle% ; 'next line of code stipulates any active Explorer class window i.e. Explorer OR Internet Explorer' ; 'the following line stipulates any active Explorer window specifically i.e. Explorer windows only, excludes Internet Explorer windows' ; 'the line after that invokes the View menu tab in the Explorer "Ribbon" with ALT+v (whether the Ribbon is minimized or not)' ; 'once the View menu tab is active, double tapping the h key toggles Show/hide Hidden items (with the necessary Sleep commands in between)' If WinClass <> CabinetWClass If WinClass <> ExploreWClass Return Send, !v Sleep, 10 Send, h Sleep, 10 Send, h Return ; 'Since this is a simple toggle, pressing WIN+h repeatedly will only toggle back and forth between Showing/hiding Hidden items in the active Explorer window'
Hi,
in order to make this work, you first have to go to Windows Explorer and clear the checkbox in 'Tools->Folder Options->View->Advanced Settings' which states 'Hide protected operating system files', so all files would be displayed if you toggle 'hidden files'.
You might have to run the script two times if you start it the first time to get the variable set right....showHidden=0 #H:: WinGetActiveTitle, WinTitle WinGetClass, WinClass, %WinTitle% If WinClass <> CabinetWClass If WinClass <> ExploreWClass Return Send, !T Sleep, 100 Send, o WinWaitActive, Folder Options,,5 if ErrorLevel = 1 Return Send, ^{Tab} Sleep, 50 Send, {Tab}{Tab} Sleep, 50 If showHidden = 0 { showHidden = 1 Send, {Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down} } Else { showHidden = 0 Send, {Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down}{Down} } sleep, 50 Send, {Space} Send, {Tab}{Tab}{Enter} ReturnCheers, Thorsten
My Scripts are written for the latest released version of AutoHotkey.
Need a secure, accessible place to backup your stuff? Use Dropbox!
Here's my take on this. I didn't wan't an intrusive GUI or a tray icon, so my script toggles the visibility of hidden files with Ctrl+Windows+H and the visibility of both hidden and system files with Shift+Ctrl+Windows+H (you can change these of course) and shows a ToolTip by the cursor showing the state of each. The script refreshes all Explorer windows (inc. the Desktop) automatically without requiring that the Explorer window be active.
I recycled and modified some of R01Z's functions.
;=================================================================================== ; Toggle visibility of hidden files in Explorer with Ctrl+Windows+H, and ; toggle visibility of both system files and hidden files with Ctrl+Shift+Windows+H. ;=================================================================================== ;============AutoExecute============ ToolTipTimeShow := 1000 ;Set the time to show the ToolTip. ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman if hwWindow { ; Win XP desktopclassname := "Progman" explorerlistview := "SysListView321" } else { ; Win 7+ desktopclassname := "WorkerW" explorerlistview := "DirectUIHWND3" } GroupAdd, ExplorerWindowsGroup, ahk_class CabinetWClass ;==========End AutoExecute========== ^#h:: ;Toggle visibility of hidden files with Ctrl+Windows+H. Keep system files hidden. RegRead, HiddenVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden ;Hidden files: 1 is visible, 2 is hidden. RegRead, SystemVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden ;System files: 1 is visible, 0 is hidden. if HiddenVisible = 2 ;If hidden files are not visible... ShowHiddenFiles(1) ;...show hidden files and hide system (superhidden) files. else if SystemVisible = 1 ;Or if system files are visible... ShowHiddenFiles(1) ;...make system files not visible and keep hidden files visible. else ShowHiddenFiles(0) ;Otherwise hide all. gosub, ShowToolTip return ^+#h:: ;Toggle visibility of hidden files and system files with Ctrl+Shift+Windows+H. RegRead, HiddenVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden RegRead, SystemVisible, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden if SystemVisible = 0 ;If system files are not visible, show both system and hidden files. ShowHiddenFiles(2) else ;Otherwise hide all. ShowHiddenFiles(0) gosub, ShowToolTip return ShowToolTip: ToolTip, Hidden Files: %HiddenFilesState%`nSystem Files: %SystemFilesState% SetTimer, RemoveToolTip, %ToolTipTimeShow% ;The ToolTipTimeShow variable is in the Autoexecute section at the top of this script. RefreshExplorerWindows()r eturn RemoveToolTip: SetTimer, RemoveToolTip, Off ToolTip return ShowHiddenFiles(mode) { ;Parameters: 0 hides all, 1 shows only hidden files, 2 shows both hidden and system files. global HiddenFilesState, SystemFilesState if (mode == 0) { RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2 RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0 ;<<Normally not necessary, but because this script relies on the registry key for the current state, the key needs to be updated every time. HiddenFilesState := "Not Visible" SystemFilesState := "Not Visible" } else if (mode == 1) { RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1 RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0 HiddenFilesState := "Visible" SystemFilesState := "Not Visible" } else { RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1 RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 1 HiddenFilesState := "Visible" SystemFilesState := "Visible" } sleep, 10 return } RefreshExplorerWindows() { global desktopclassname, explorerlistview ControlSend, ahk_parent, {F5}, ahk_class %desktopclassname% ; refresh Desktop ControlSend, %explorerlistview%, {F5}, ahk_group ExplorerWindowsGroup ; refresh all Explorer windows ControlSend, DirectUIHWND3, {F5}, ahk_group ExplorerWindowsGroup ; refresh all Explorer windows }
Find me at the other forum as timeFlies.
WinGet, ListId , List, ahk_exe explorer.exe Loop % ListId ControlSend, SysTreeView321, {f5}, % "ahk_id " ListId%A_Index% ControlSend, ahk_parent, {f5}, Program Manager ahk_exe explorer.exeelse
for window in ComObjCreate("Shell.Application").Windows ControlSend, SysTreeView321, {f5}, % "ahk_id " window.hwnd ControlSend,, {f5}, Program Manager ahk_exe explorer.exeexample my script
^#h:: ;Toggle visibility of hidden files with Ctrl+Windows+H. Keep system files hidden. RegRead, H, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0 HiddenFiles(H, (H = 2 ? "" : "System & ") "Hidden files") Return ^+#h:: ;Toggle visibility of hidden files and system files with Ctrl+Shift+Windows+H. RegRead, H, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, % (H = 2) ? 1 : 0 HiddenFiles(H, "System & Hidden files") Return HiddenFiles(H, T) { RegWrite, REG_DWORD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, % (H = 2) ? 1 : 2 for window in ComObjCreate("Shell.Application").Windows ControlSend, SysTreeView321, {f5}, % "ahk_id " window.hwnd ControlSend,, {f5}, Program Manager ahk_exe explorer.exe TrayTip, % T, % (H = 2) ? "Show" : "Hide", 1, 1 }