Hi guys,
Does anyone know how to achieve this:
1. I click in a folder, either in Windows Explorer or in XYplorer
2. press a keyboard shortcut
2a. a new .docx file is created in the current folder
or
2b. a .docx somewhere on my computer is copied into the current folder
Any pointers would be greatly appreciated!
Michael
Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut? Topic is solved
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Hi, @michaelbeijer, I have something for v1 that I got from the forum, still looking for the link. In the meantime, this may give you some ideas.
The script I was looking for is at this page.
The script I was looking for is at this page.
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Thanks @burque505! I'll have a look!
I also found this: viewtopic.php?f=76&t=101873&p=555936#p555936 … which sort of works, albeit not reliably, and also not in XYplorer (although I think I can fix that by getting the window class for XYplorer with Window Spy; not sure how to make it work in multiple file explorers at once though).
I also found this: viewtopic.php?f=76&t=101873&p=555936#p555936 … which sort of works, albeit not reliably, and also not in XYplorer (although I think I can fix that by getting the window class for XYplorer with Window Spy; not sure how to make it work in multiple file explorers at once though).
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
You might try this to add XYPlorer :
I don't have XYPlorer installed anymore, so I can't check the 'ahk_class'.
(Volgens mij moet dat 'ahk_class ThunderRT6FormDC' zijn voor XYPlorer, maar dat zal niet veel helpen. Te veel apps hebben dat als 'ahk_class'.)
Code: Select all
If WinActive("ahk_class CabinetWClass") OR WinActive("ahk_class Progman") OR WinActive("ahk_class WorkerW") OR WinActive("ahk_exe XYplorer.exe) {
; Do stuff
}
(Volgens mij moet dat 'ahk_class ThunderRT6FormDC' zijn voor XYPlorer, maar dat zal niet veel helpen. Te veel apps hebben dat als 'ahk_class'.)
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Thanks/bedankt!
inderdaad:
ahk_class ThunderRT6FormDC
ahk_exe XYplorer.exe
ahk_pid 14800
ahk_id 460124
inderdaad:
ahk_class ThunderRT6FormDC
ahk_exe XYplorer.exe
ahk_pid 14800
ahk_id 460124
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Code: Select all
^+n::
flnm := "comments.docx"
if !(path := getpath()) or (fileexist(path "\" flnm))
return
oWord := ComObjCreate("word.application")
oWord.Documents.Add
oWord.Visible := True
oword.activeDocument.SaveAs(path "\" flnm)
return
getpath() {
WinGetClass class, % "ahk_id " hwnd := WinExist("A")
if (class ~= "CabinetWClass") OR (class ~= "ThunderRT6FormDC") OR (ahk_exe ~= "XYplorer.exe")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
return window.Document.Folder.Self.Path
}
this was the original I found online:
Code: Select all
^+n::
flnm := "comments.docx"
if !(path := getpath()) or (fileexist(path "\" flnm))
return
oWord := ComObjCreate("word.application")
oWord.Documents.Add
oWord.Visible := True
oword.activeDocument.SaveAs(path "\" flnm)
return
getpath() {
WinGetClass class, % "ahk_id " hwnd := WinExist("A")
if (class ~= "(Cabinet|Explore)WClass")
for window in ComObjCreate("Shell.Application").Windows
if (window.hwnd==hwnd)
return window.Document.Folder.Self.Path
}
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut? Topic is solved
Code: Select all
#Requires AutoHotkey v2
; Explorer ------------------------------
^+n::
{
flnm := "comments.docx"
if !(path := getpath()) or (fileexist(path "\" flnm))
return
oWord := ComObject("word.application")
oWord.Documents.Add
oWord.Visible := True
oword.activeDocument.SaveAs(path "\" flnm)
return
}
getpath() {
class := WinGetClass("ahk_id " hwnd := WinExist("A"))
if (class ~= "(Cabinet|Explore)WClass")
for window in ComObject("Shell.Application").Windows
if (window.hwnd==hwnd)
return window.Document.Folder.Self.Path
}
; XYplorer ------------------------------
; Get the hwnd of the script
G_OwnHWND := A_ScriptHwnd
; Get messages back from XYplorer
OnMessage(0x4a, Receive_WM_COPYDATA)
dataReceived := "", programPath := ""
#HotIf winActive("ahk_class ThunderRT6FormDC")
^+n::
{
flnm := "comments.docx"
if !(path := XY_Get(false, false)) or (fileexist(path "\" flnm))
return
oWord := ComObject("word.application")
oWord.Documents.Add
oWord.Visible := True
oword.activeDocument.SaveAs(path "\" flnm)
return
}
#HotIf
XY_Get(bAll:=false, bSelection:=false)
{
xyQueryScript := '::if (!' bAll ' && !' bSelection ') {$return = "<curpath>"`;} elseif (' bAll ') {$return = listpane(, , , "<crlf>")`;} elseif (' bSelection ') {$return = get("SelectedItemsPathNames", "<crlf>")`;} copydata ' G_OwnHWND ', "$return", 2`;'
if xyHwnd := GetXYHWND()
Send_WM_COPYDATA(xyHwnd, xyQueryScript)
return dataReceived
}
GetXYHWND() {
static xyClass := 'ahk_class ThunderRT6FormDC'
if WinExist(xyClass) {
for xyid in WinGetList(xyClass)
for ctrl in WinGetControls(xyid)
if A_Index = 10
return xyid
}
}
Send_WM_COPYDATA(xyHwnd, message) {
if !(xyHwnd)
return
size := StrLen(message)
COPYDATA := Buffer(A_PtrSize * 3)
NumPut("Ptr", 4194305, COPYDATA, 0)
NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
NumPut("Ptr", StrPtr(message), COPYDATA, A_PtrSize * 2)
return DllCall("User32.dll\SendMessageW", "Ptr", xyHwnd, "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "Ptr")
}
Receive_WM_COPYDATA(wParam, lParam, *) {
global dataReceived := StrGet(
NumGet(lParam + 2 * A_PtrSize, 'Ptr'), ; COPYDATASTRUCT.lpData, ptr to a str presumably
NumGet(lParam + A_PtrSize, 'UInt') / 2 ; COPYDATASTRUCT.cbData, count bytes of lpData, /2 to get count chars in unicode str
)
}
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Thanks so much @WKen! It works perfectly.
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
re: the windows version you found here viewtopic.php?f=76&t=101873&p=555936#p452877 . You say " which sort of works, albeit not reliably", then later, quoting the same code (except for the references to ThunderRT6FormDC and XYplorer.exe), you say "It works pretty reliably in Windows Explorer". Then in response to Wken's post which includes the Windows version I posted, you say "It works perfectly". So which one it it?
14.3 & 1.3.7
- michaelbeijer
- Posts: 83
- Joined: 04 Oct 2014, 08:01
- Location: Hastings, UK.
- Contact:
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Ha ha, I think I was confused because if the file (comments.docx) is already in the folder, it won't create a second one. This led me to believe the script wasn't always working. To confuse matters more, I was also trying to run it from inside my multi-script launching script*, which didn't work. (*this one: AHK Startup, by Fanatic Guru @ viewtopic.php?style=19&f=6&t=788&start=100)
Michael Beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Dutch-English technical translator
Hastings, United Kingdom
Email: michael[at]beijer.uk
Website: Beijer.uk
Terminology: Beijerterm.com
AHK-learning project: Beijer.bot
Proz profile: proz.com/profile/652138
LinkedIn: linkedin.com/in/michael-beijer
Re: Create new empty.docx (or copy empty.docx saved somewhere on my computer) in(to) current folder with shortcut?
Try:
Code: Select all
#Requires AutoHotkey v2
; Create new document -------------------
new_docx(path) {
flnm := "comments"
filePath := path "\" flnm ".docx"
if fileExist(filePath) {
loop
{
filePath := path "\" flnm "-0" A_Index ".docx"
if !fileExist(filePath)
break
}
}
oWord := ComObject("word.application")
oWord.Documents.Add
oWord.Visible := True
oword.activeDocument.SaveAs(filePath)
return
}
; Explorer ------------------------------
^+n::
{
if !path := getpath()
return
new_docx(path)
}
getpath() {
class := WinGetClass("ahk_id " hwnd := WinExist("A"))
if (class ~= "(Cabinet|Explore)WClass")
for window in ComObject("Shell.Application").Windows
if (window.hwnd==hwnd)
return window.Document.Folder.Self.Path
}
; XYplorer ------------------------------
; Get the hwnd of the script
G_OwnHWND := A_ScriptHwnd
; Get messages back from XYplorer
OnMessage(0x4a, Receive_WM_COPYDATA)
dataReceived := ""
#HotIf winActive("ahk_class ThunderRT6FormDC")
^+n::
{
flnm := "comments.docx"
if !path := XY_Get(false, false)
return
new_docx(path)
}
#HotIf
XY_Get(bAll:=false, bSelection:=false)
{
xyQueryScript := '::if (!' bAll ' && !' bSelection ') {$return = "<curpath>"`;} elseif (' bAll ') {$return = listpane(, , , "<crlf>")`;} elseif (' bSelection ') {$return = get("SelectedItemsPathNames", "<crlf>")`;} copydata ' G_OwnHWND ', "$return", 2`;'
if xyHwnd := GetXYHWND()
Send_WM_COPYDATA(xyHwnd, xyQueryScript)
return dataReceived
}
GetXYHWND() {
static xyClass := 'ahk_class ThunderRT6FormDC'
if WinExist(xyClass) {
for xyid in WinGetList(xyClass)
for ctrl in WinGetControls(xyid)
if A_Index = 10
return xyid
}
}
Send_WM_COPYDATA(xyHwnd, message) {
if !(xyHwnd)
return
size := StrLen(message)
COPYDATA := Buffer(A_PtrSize * 3)
NumPut("Ptr", 4194305, COPYDATA, 0)
NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
NumPut("Ptr", StrPtr(message), COPYDATA, A_PtrSize * 2)
return DllCall("User32.dll\SendMessageW", "Ptr", xyHwnd, "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "Ptr")
}
Receive_WM_COPYDATA(wParam, lParam, *) {
global dataReceived := StrGet(
NumGet(lParam + 2 * A_PtrSize, 'Ptr'), ; COPYDATASTRUCT.lpData, ptr to a str presumably
NumGet(lParam + A_PtrSize, 'UInt') / 2 ; COPYDATASTRUCT.cbData, count bytes of lpData, /2 to get count chars in unicode str
)
}
Who is online
Users browsing this forum: akirofe and 44 guests