Pasting clipboard contents into freshly-created file Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
HumbleHedgehog
Posts: 2
Joined: 22 Oct 2021, 16:36

Pasting clipboard contents into freshly-created file

22 Oct 2021, 17:31

Hello! Trying to simplify a process and running into a bit of a snag. I need to create a text file in the same folder as the script, paste the current contents of the clipboard into it, save it, close, and then make a subfolder with the same name as the created text file and move all .jpg and .txt files (should only ever be one of the latter at a time) currently in the folder into the newly-created subfolder. There'll be many of these, so they'll have to be named distinctly (hence the A_Now).

Where I've run into the issue at the moment is the second step: I can get the file to create in the script's folder and open fine, but no matter what I try it won't seem to paste. Send, ^v doesn't seem to be working, nor do some other variations I've tried: everything else I've included below for reference. Any suggestions would be greatly appreciated!

(Full disclosure: never tried anything of the sort before, only just managed to Frankenstein things so far, so advance apologies for any obvious errors or weirdness)

Code: Select all

^x::
vPathNotepad := "C:\Program Files (x86)\Notepad++\notepad++.exe"
vPath := A_ScriptDir "\z " A_Now ".txt"
if FileExist(vPath)
{
	MsgBox, % "error: file already exists:`r`n" vPath
	return
}
FileAppend,, % "*" vPath, UTF-8
Run, "%vPathNotepad%" "%vPath%"
Send, ^v
return
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Pasting clipboard contents into freshly-created file

22 Oct 2021, 19:33

why not:

Code: Select all

vPath := A_ScriptDir "\z " A_Now ".txt"
FileAppend, %clipboard%, %vPath%, UTF-8
Run, %vPath%
return
??
14.3 & 1.3.7
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Pasting clipboard contents into freshly-created file  Topic is solved

22 Oct 2021, 19:57

Welcome to AHK!

Code: Select all

^x::
fn := "z " A_Now, dir := A_ScriptDir "\" fn, file := dir "\" fn ".txt"
FileCreateDir, %dir%
If ErrorLevel {
 MsgBox, 48, Failure, An error occurred when creating the directory. Aborting.`n`n%dir%
 Return
} Else FileAppend, %Clipboard%, *%file%, UTF-8
Loop, Files, %A_ScriptDir%\*.*
{ ToolTip, %A_Index%
  If A_LoopFileExt not in jpg,txt
   Continue
  FileMove, %A_LoopFilePath%, %dir%
  If ErrorLevel
   MsgBox, 48, Error, An error occurred while moving the file.`n`n%A_LoopFilePath%
}
ToolTip
MsgBox, 64, Done, Done!
Return
HumbleHedgehog
Posts: 2
Joined: 22 Oct 2021, 16:36

Re: Pasting clipboard contents into freshly-created file

22 Oct 2021, 20:13

mikeyww wrote:
22 Oct 2021, 19:57
Welcome to AHK!
Thank you very much for the assistance and the kind welcome (both of you)! That worked flawlessly. I can't even begin to count the amount of hours this has saved: fantastic, and many, many, many thanks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 169 guests