; Shortcuts like mac ; Written by m2nlight ; https://github.com/m2nlight/AHKShortcutLikeMac #SingleInstance Off #HotkeyInterval 2000 #HotkeyModifierTimeout 100 SetWorkingDir, %A_ScriptDir% global my_name := "MacHotKey" global my_version := "v0.3.1" global my_bit := A_PtrSize * 8 global my_website := "https://github.com/m2nlight/AHKShortcutLikeMac" if A_Args.Length() > 0 { #NoEnv #Persistent try { cmd := A_Args[1] if (cmd = "movefiles") { ShellMoveFile() } else if (cmd = "emptybin") { EmptyBin() } else if (cmd = "silentemptybin") { EmptyBin(true) } else if (cmd = "SwitchHiddenFiles") { SwitchHiddenFiles() Send {F5} } else if (cmd = "help" or cmd = "version") { ShowHelp() } else { ExitApp, 1 } } ExitApp } ; ## Special Key ## #F1::Send #x ; Show WinX menu in win10 #F2::Send #r ; Show run dialog #`::NextWindow() ; ## Menu ## #H::WinMinimize, A !#H::HideOtherWindow() #M::WinMinimize, A !#M::WinMinimizeAll #Q::Send !{F4} ; File #T::Send ^t +#T::Send +^t #N::Send ^n +#N::Send +^n #O::Send ^o #W::Send ^w #+W::Send #w #S::Send ^s #P::Send ^p #+P::Send #p ; Edit #Z::Send ^z +#Z::Send ^y #X::Send ^x #C::Send ^c #V::Send ^v !+#V:: clipboard = %clipboard% Send ^v return #A::Send ^a #F::Send ^f #G::Send {F3} +#G::Send +{F3} !#F::Send ^h #Left::Send {Home} #Right::Send {End} #Up::Send {PgUp} #Down::Send {PgDn} 0) { last := pExp.LocationURL } } } } if(getLastWhenNoFound and last) { return last } } ConvertExplorerURLToPath(url) { If !url Return "" path := url path := RegExReplace(path, "ftp://.*@","ftp://") StringReplace, path, path, file:/// StringReplace, path, path, /, \, All Loop If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex) StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All Else Break Return path } ActiveControlIs(Control) { ControlGetFocus, FocusedControl, A return (FocusedControl=Control) } ActiveControlIsOfClass(Class) { ControlGetFocus, FocusedControl, A ControlGet, FocusedControlHwnd, Hwnd,, %FocusedControl%, A WinGetClass, FocusedControlClass, ahk_id %FocusedControlHwnd% return (FocusedControlClass=Class) } GeneratePassword(length, withSpecialChars=false) { Characters = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 if withSpecialChars { Characters .= "``~!@#$`%^&*()_+-=[]{}\|`;:'""`,.<>/?" } Loop %length% { Random, r, 1, % StrLen(Characters) Passwords .= SubStr(Characters, r, 1) } SendInput {Raw}%Passwords% } SetTransparent(value) { if (value is not integer) { return } if (value >= 100 or value < 0) { WinSet, Transparent, 255, A return } value := value*255//100 WinSet, Transparent, %value%, A } RunNewInstance(cmd, runAsAdmin = false) { If A_IsCompiled { if (runAsAdmin && not A_IsAdmin) { try { Run *RunAs %A_ScriptFullPath% %cmd% } return } Run %A_ScriptFullPath% %cmd% return } if (runAsAdmin && not A_IsAdmin) { try { Run *RunAs %A_AhkPath% %A_ScriptFullPath% %cmd% } return } Run %A_AhkPath% %A_ScriptFullPath% %cmd% } SwitchHiddenFiles() { SetRegView %my_bit% try { RegRead, OutputVar, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden } catch { OutputVar = 0 } if (OutputVar and OutputVar = 1) { RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 0 RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 2 } else { RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, ShowSuperHidden, 1 RegWrite, REG_DWORD, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced, Hidden, 1 } } CheckMoveFile() { target_dir := RealCurrentPath() if StrLen(target_dir) = 0 { return false } source_files := "" Loop, parse, clipboard, `n, `r { IfNotExist, %A_LoopField%, continue source_files = %source_files%%A_LoopField%| } if StrLen(source_files) = 0 { return false } return true } ShellMoveFile() { target_dir := RealCurrentPath() if StrLen(target_dir) = 0 { return } ; fix network path "file://ipaddress/path" to "\\ipaddress\path" StringReplace, target_dir, target_dir, file:, , All StringReplace, target_dir, target_dir, /, \, All source_files := "" Loop, parse, clipboard, `n, `r { IfNotExist, %A_LoopField%, continue source_files = %source_files%%A_LoopField%| } if StrLen(source_files) = 0 { return } ;msgbox Will to move %source_files% to %target_dir% ShellFileOperation("FO_MOVE", source_files, target_dir,"FOF_ALLOWUNDO|FOF_SIMPLEPROGRESS|FOF_NOCONFIRMMKDIR") } ; https://autohotkey.com/board/topic/51486-shellfileoperation-library/ ; https://github.com/7plus/7plus/blob/f3b270f7b182d2ad023efb00f51e6f77b3029520/Shell.ahk ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb759795(v=vs.85).aspx ; ShellFileOperation("FO_MOVE", "::::", "::::","FOF_ALLOWUNDO|FOF_SIMPLEPROGRESS|FOF_NOCONFIRMMKDIR") ; MsgBox % ErrorLevel ShellFileOperation( fileO=0x0, fSource="", fTarget="", flags=0x0, ghwnd=0x0 ) { ;dout_f(A_ThisFunc) FO_MOVE := 0x1 FO_COPY := 0x2 FO_DELETE := 0x3 FO_RENAME := 0x4 FOF_MULTIDESTFILES := 0x1 ; Indicates that the to member specifies multiple destination files (one for each source file) rather than one directory where all source files are to be deposited. FOF_SILENT := 0x4 ; Does not display a progress dialog box. FOF_RENAMEONCOLLISION := 0x8 ; Gives the file being operated on a new name (such as "Copy #1 of...") in a move, copy, or rename operation if a file of the target name already exists. FOF_NOCONFIRMATION := 0x10 ; Responds with "yes to all" for any dialog box that is displayed. FOF_ALLOWUNDO := 0x40 ; Preserves undo information, if possible. With del, uses recycle bin. FOF_FILESONLY := 0x80 ; Performs the operation only on files if a wildcard filename (*.*) is specified. FOF_SIMPLEPROGRESS := 0x100 ; Displays a progress dialog box, but does not show the filenames. FOF_NOCONFIRMMKDIR := 0x200 ; Does not confirm the creation of a new directory if the operation requires one to be created. FOF_NOERRORUI := 0x400 ; don't put up error UI FOF_NOCOPYSECURITYATTRIBS := 0x800 ; dont copy file security attributes FOF_NORECURSION := 0x1000 ; Only operate in the specified directory. Don't operate recursively into subdirectories. FOF_NO_CONNECTED_ELEMENTS := 0x2000 ; Do not move connected files as a group (e.g. html file together with images). Only move the specified files. FOF_WANTNUKEWARNING := 0x4000 ; Send a warning if a file is being destroyed during a delete operation rather than recycled. This flag partially overrides FOF_NOCONFIRMATION. ; no more annoying numbers to deal with (but they should still work, if you really want them to) fileO := %fileO% ? %fileO% : fileO ; the double ternary was too fun to pass up _flags := 0 Loop Parse, flags, | _flags |= %A_LoopField% flags := _flags ? _flags : (%flags% ? %flags% : flags) If ( SubStr(fSource,0) != "|" ) fSource := fSource . "|" If ( SubStr(fTarget,0) != "|" ) fTarget := fTarget . "|" char_size := A_IsUnicode ? 2 : 1 char_type := A_IsUnicode ? "UShort" : "Char" fsPtr := &fSource Loop % StrLen(fSource) if NumGet(fSource, (A_Index-1)*char_size, char_type) = 124 NumPut(0, fSource, (A_Index-1)*char_size, char_type) ftPtr := &fTarget Loop % StrLen(fTarget) if NumGet(fTarget, (A_Index-1)*char_size, char_type) = 124 NumPut(0, fTarget, (A_Index-1)*char_size, char_type) /* typedef struct _SHFILEOPSTRUCT { HWND hwnd; A_PtrSize UINT wFunc; 4 PCZZTSTR pFrom; <-- LPCWSTR, A_PtrSize PCZZTSTR pTo; A_PtrSize FILEOP_FLAGS fFlags; <-- WORD, 2 BOOL fAnyOperationsAborted;, 4 LPVOID hNameMappings; A_PtrSize PCTSTR lpszProgressTitle; A_PtrSize } SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT; Total: A_PtrSize + 4 (+ 4 Padding) Padding + A_PtrSize + A_PtrSize + 2 + 2 Padding + 4 + A_PtrSize + A_PtrSize = 12 (+4) + 5 x A_PtrSize */ VarSetCapacity( SHFILEOPSTRUCT, 12 + 5 * A_PtrSize, 0) ; Encoding SHFILEOPSTRUCT NumPut( ghwnd, &SHFILEOPSTRUCT, "PTR") ; hWnd of calling GUI NumPut( fileO, SHFILEOPSTRUCT, A_PtrSize, "UINT") ; File operation NumPut( fsPtr, SHFILEOPSTRUCT, 2 * A_PtrSize, "PTR") ; Source file / pattern NumPut( ftPtr, SHFILEOPSTRUCT, 3 * A_PtrSize, "PTR" ) ; Target file / folder NumPut( flags, SHFILEOPSTRUCT, 4 * A_PtrSize, "Short" ) ; options DllCall( "Shell32\SHFileOperation" . (A_IsUnicode ? "W" : "A"), Ptr, &SHFILEOPSTRUCT ) SHFILEOPSTRUCT := "" Return }