AutoHotkey - 使用 Notepad++ 打开 html 文件,然后查找并替换,然后保存,关闭。将其包含在另一个脚本中
AutoHotkey - Open html file with Notepad++ then find and replace, then save, close. Include this in another script
1. 在文件夹“2”中,我想用 Notepad++ 打开选定的 "example.html" 文件。或者第二个鼠标按钮 --> 使用记事本++编辑
2.然后找到"big"这个词替换成"small",保存退出Notepad++和return到一个文件夹" 2".
当 html 文件被选中时 - 一个快捷键如何完成前 2 个步骤。
没有将其实现到另一个脚本中。
3. 以及如何在将内容压缩并移动到 "FINAL" 文件夹之前使用此脚本执行上述脚本。因为其中一个文件有 html 文件,我需要在其中执行上述两个步骤。我想脚本应该在 "Send ^a ; Select All" part.
之前开始
#IfWinActive ahk_class CabinetWClass
F4::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
IfNotExist, %Fullpath%
{
MsgBox, The folder "%Fullpath%" doesn't exist
return
}
Run, %Fullpath%
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
StringReplace, Fullpath2, Fullpath, :,
StringSplit, folder_array, Fullpath2, \,
FolderName = % folder_array%folder_array0%
; MsgBox, % folder_array%folder_array0%
; Sleep 2000 ; wait 2 seconds
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
Send {Enter}
SetTimer, Move_ZIP, 500
return
#IfWinActive
Move_ZIP:
FileCreateDir %A_Desktop%\FINAL
IfExist, %Fullpath%\%FolderName%.zip
{
SetTimer, Move_ZIP, off
FileMove, %Fullpath%\%FolderName%.zip, %A_Desktop%\FINAL
Sleep 2000 ; wait 2 seconds
SetTimer, CopyDir, 500
}
return
CopyDir:
IfExist, %Fullpath%\%FolderName%.zip
return
SetTimer, CopyDir, off
FileCopyDir %Fullpath%, %A_Desktop%\FINAL\%FolderName%
return
; ...
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
FileRead, Contents, %Fullpath%\example.html
if not ErrorLevel ; Successfully loaded
{
StringReplace, Contents, Contents, big, small ; replace only the first occurrence
; OR :
; StringReplace, Contents, Contents, big, small, All ; replace all occurrences
FileAppend, %Contents%, %Fullpath%\example2.html
Contents = ; Free the memory
}
FileMove, %Fullpath%\example2.html, %Fullpath%\example.html, 1 ; overwrite existing file
StringReplace, Fullpath2, Fullpath, :,
; ...
https://autohotkey.com/docs/commands/FileRead.htm
1. 在文件夹“2”中,我想用 Notepad++ 打开选定的 "example.html" 文件。或者第二个鼠标按钮 --> 使用记事本++编辑
2.然后找到"big"这个词替换成"small",保存退出Notepad++和return到一个文件夹" 2".
当 html 文件被选中时 - 一个快捷键如何完成前 2 个步骤。 没有将其实现到另一个脚本中。
3. 以及如何在将内容压缩并移动到 "FINAL" 文件夹之前使用此脚本执行上述脚本。因为其中一个文件有 html 文件,我需要在其中执行上述两个步骤。我想脚本应该在 "Send ^a ; Select All" part.
之前开始#IfWinActive ahk_class CabinetWClass
F4::
for window in ComObjCreate("Shell.Application").Windows
try Fullpath := % window.Document.Folder.Self.Path
IfNotExist, %Fullpath%
{
MsgBox, The folder "%Fullpath%" doesn't exist
return
}
Run, %Fullpath%
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
StringReplace, Fullpath2, Fullpath, :,
StringSplit, folder_array, Fullpath2, \,
FolderName = % folder_array%folder_array0%
; MsgBox, % folder_array%folder_array0%
; Sleep 2000 ; wait 2 seconds
Send ^a ; Select All
Send, {AppsKey} ; Press the "context menu" key
Sleep 100
Send n ; Select "Send to" with the "n" key
Sleep 100
Send {Right} ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down} ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter} ; Execute "Compressed (zipped) folder" with the "Enter" key
Sleep 2000 ; wait 2 seconds
SendInput, % folder_array%folder_array0%
Send {Enter}
SetTimer, Move_ZIP, 500
return
#IfWinActive
Move_ZIP:
FileCreateDir %A_Desktop%\FINAL
IfExist, %Fullpath%\%FolderName%.zip
{
SetTimer, Move_ZIP, off
FileMove, %Fullpath%\%FolderName%.zip, %A_Desktop%\FINAL
Sleep 2000 ; wait 2 seconds
SetTimer, CopyDir, 500
}
return
CopyDir:
IfExist, %Fullpath%\%FolderName%.zip
return
SetTimer, CopyDir, off
FileCopyDir %Fullpath%, %A_Desktop%\FINAL\%FolderName%
return
; ...
WinWait, %Fullpath%
WinActivate, %Fullpath%
WinWaitActive,%Fullpath%
FileRead, Contents, %Fullpath%\example.html
if not ErrorLevel ; Successfully loaded
{
StringReplace, Contents, Contents, big, small ; replace only the first occurrence
; OR :
; StringReplace, Contents, Contents, big, small, All ; replace all occurrences
FileAppend, %Contents%, %Fullpath%\example2.html
Contents = ; Free the memory
}
FileMove, %Fullpath%\example2.html, %Fullpath%\example.html, 1 ; overwrite existing file
StringReplace, Fullpath2, Fullpath, :,
; ...
https://autohotkey.com/docs/commands/FileRead.htm