variables copied from clipboard change unless I use msgbox to display them - why?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dwilbank
Posts: 43
Joined: 15 Mar 2020, 12:59

variables copied from clipboard change unless I use msgbox to display them - why?

Post by dwilbank » 27 Jan 2023, 18:49

So here's some working code, (highlight files, then alt-f to wrap them in a folder)

but if I take out the msgboxes, the value of fileList is the most recent clipboard value from line 7, instead of retaining the list of selected files I assigned it in line 3

did I not "lock in" the value of fileList properly in line 3?

Code: Select all

!f::
send ^c; get filepath list
fileList := clipboard
sleep 100
Send ^l; goto current directory field
sleep 100
send ^c; get current directory
clipwait
InputBox, folder, folder
folder := RegExReplace(folder, "/", "\")
FileCreateDir, %clipboard%\%folder%
sleep 500
msgbox %fileList% <----------------------------- why necessary?
Loop, parse, fileList, `n, `r
{
        msgbox %A_LoopField% <-------------------- why necessary?
        SplitPath A_LoopField, OutFileName, OutDir, OutExtension, OutNameNoExt, OutDrive
               ;OutNameNoExtFix = RegExReplace(OutNameNoExt, " ", "_");
        FileMove %A_LoopField%, %clipboard%\%folder%\%OutNameNoExt%.%OutExtension%
}
return

User avatar
mikeyww
Posts: 26612
Joined: 09 Sep 2014, 18:38

Re: variables copied from clipboard change unless I use msgbox to display them - why?

Post by mikeyww » 27 Jan 2023, 20:09

Hello,

The documentation for ClipWait includes an example of how to use the command properly. This includes clearing the clipboard.

To get a control's text: ControlGetText

dwilbank
Posts: 43
Joined: 15 Mar 2020, 12:59

Re: variables copied from clipboard change unless I use msgbox to display them - why?

Post by dwilbank » 27 Jan 2023, 20:17

ControlGetText is something I was going to tackle soon - thanks!

but it's

Code: Select all

fileList
that is losing its value - not my clipboard

User avatar
mikeyww
Posts: 26612
Joined: 09 Sep 2014, 18:38

Re: variables copied from clipboard change unless I use msgbox to display them - why?

Post by mikeyww » 27 Jan 2023, 20:41

If fileList equals clipboard and clipboard equals nothing, then where does that leave fileList?

No need to wonder. You can just fix the script instead, right? :)

dwilbank
Posts: 43
Joined: 15 Mar 2020, 12:59

Re: variables copied from clipboard change unless I use msgbox to display them - why?

Post by dwilbank » 27 Jan 2023, 21:05

Running the code shows that clipboard equals first one thing, then the other... never 'nothing'.

Just like fileList is first one value, then it becomes a second value for no clear reason

User avatar
mikeyww
Posts: 26612
Joined: 09 Sep 2014, 18:38

Re: variables copied from clipboard change unless I use msgbox to display them - why?

Post by mikeyww » 27 Jan 2023, 21:54

Comments:
Comments may also be added at the end of a line, in which case the semicolon must have at least one space or tab to its left.

Post Reply

Return to “Ask for Help (v1)”