Advertisement
Guest User

Untitled

a guest
Jun 11th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Persistent
  2.  
  3. NumberToDivideBy = 55
  4.  
  5. #1:: ;Hotkey for WinKey + 1.
  6. PathToFile := Explorer_GetSelected()
  7. ifEqual, PathToFile, ERROR
  8. {
  9.     Msgbox, You havent selected any files.
  10.     Exitapp
  11. }
  12.  
  13. StringGetPos, LocOfPoint, PathToFile, ., R1
  14. StringTrimLeft, FileExt, PathToFile, %LocOfPoint%
  15. MsgBox, %FileExt%
  16. ifEqual, FileExt, .docx
  17. {
  18.     w := ComObjCreate( "Word.Application" )
  19.     w.Documents.Open( PathToFile )      
  20.     FileContents := w.ActiveDocument.Content.Text
  21.     w.Options.SaveNormalPrompt ? "True" : "False"
  22.     w.Options.SaveNormalPrompt := ! w.Options.SaveNormalPrompt
  23.     w.Options.SaveNormalPrompt ? "True" : "False"
  24.     w.Quit
  25.     w.Tasks( "Word" ).Close
  26. }
  27.  
  28. FileRead, FileContents, %PathToFile% ;Reads the files contents to a variable.
  29.  
  30. ifEqual, FileExt, .docx
  31. {
  32.     goto, ReadFromWord
  33. }
  34.  
  35. ifEqual, FileExt, .doc
  36. {
  37.     goto, ReadFromWord
  38. }
  39.  
  40. ifEqual, FileExt, .docs
  41. {
  42.     goto, ReadFromWord
  43. }
  44.  
  45. ifEqual, FileExt, .docm
  46. {
  47.     goto, ReadFromWord
  48. }
  49.  
  50. StringLen, ContentLen, FileContents ;Finds the charachter count of that variable.
  51.  
  52. ContentLen /= NumberToDivideBy ;Divides by 55
  53.  
  54. MsgBox, 36, Length of the Contents, Heres the charachter count of the file divided by 55: %ContentLen%`n`nWould you like to copy it to your clipboard? ;Shows a message box.
  55. IfMsgBox, Yes ;If you answer Yes
  56.     Clipboard := ContentLen ;Set clipboard to the lenght divided by 55
  57. return
  58.  
  59. /*
  60.     Library for getting info from a specific explorer window (if window handle not specified, the currently active
  61.     window will be used).  Requires AHK_L or similar.  Works with the desktop.  Does not currently work with save
  62.     dialogs and such.
  63.    
  64.    
  65.     Explorer_GetSelected(hwnd="")   - paths of target window's selected items
  66.     Explorer_GetAll(hwnd="")        - paths of all items in the target window's folder
  67.     Explorer_GetPath(hwnd="")       - path of target window's folder
  68.    
  69.     example:
  70.         F1::
  71.             path := Explorer_GetPath()
  72.             all := Explorer_GetAll()
  73.             sel := Explorer_GetSelected()
  74.             MsgBox % path
  75.             MsgBox % all
  76.             MsgBox % sel
  77.         return
  78.    
  79.     Joshua A. Kinnison
  80.     2011-04-27, 16:12
  81. */
  82.  
  83. ReadFromWord:
  84. w := ComObjCreate( "Word.Application" )
  85. w.Documents.Open( PathToFile )      
  86. FileContents := w.ActiveDocument.Content.Text
  87. w.Options.SaveNormalPrompt ? "True" : "False"
  88. w.Options.SaveNormalPrompt := ! w.Options.SaveNormalPrompt
  89. w.Options.SaveNormalPrompt ? "True" : "False"
  90. w.Quit
  91. w.Tasks( "Word" ).Close
  92. return
  93.  
  94. Explorer_GetPath(hwnd="")
  95. {
  96.     if !(window := Explorer_GetWindow(hwnd))
  97.         return ErrorLevel := "ERROR"
  98.     if (window="desktop")
  99.         return A_Desktop
  100.     path := window.LocationURL
  101.     path := RegExReplace(path, "ftp://.*@","ftp://")
  102.     StringReplace, path, path, file:///
  103.     StringReplace, path, path, /, \, All
  104.    
  105.     ; thanks to polyethene
  106.     Loop
  107.         If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
  108.             StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
  109.         Else Break
  110.     return path
  111. }
  112.  
  113. Explorer_GetAll(hwnd="")
  114. {
  115.     return Explorer_Get(hwnd)
  116. }
  117.  
  118. Explorer_GetSelected(hwnd="")
  119. {
  120.     return Explorer_Get(hwnd,true)
  121. }
  122.  
  123. Explorer_GetWindow(hwnd="")
  124. {
  125.     ; thanks to jethrow for some pointers here
  126.     WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
  127.     WinGetClass class, ahk_id %hwnd%
  128.    
  129.     if (process!="explorer.exe")
  130.         return
  131.     if (class ~= "(Cabinet|Explore)WClass")
  132.     {
  133.         for window in ComObjCreate("Shell.Application").Windows
  134.             if (window.hwnd==hwnd)
  135.                 return window
  136.     }
  137.     else if (class ~= "Progman|WorkerW")
  138.         return "desktop" ; desktop found
  139. }
  140.  
  141. Explorer_Get(hwnd="",selection=false)
  142. {
  143.     if !(window := Explorer_GetWindow(hwnd))
  144.         return ErrorLevel := "ERROR"
  145.     if (window="desktop")
  146.     {
  147.         ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
  148.         if !hwWindow ; #D mode
  149.             ControlGet, hwWindow, HWND,, SysListView321, A
  150.         ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
  151.         base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
  152.         Loop, Parse, files, `n, `r
  153.         {
  154.             path := base "\" A_LoopField
  155.             IfExist %path% ; ignore special icons like Computer (at least for now)
  156.                 ret .= path "`n"
  157.         }
  158.     }
  159.     else
  160.     {
  161.         if selection
  162.             collection := window.document.SelectedItems
  163.         else
  164.             collection := window.document.Folder.Items
  165.         for item in collection
  166.             ret .= item.path "`n"
  167.     }
  168.     return Trim(ret,"`n")
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement