Autohotkey 将组合框变量存储为文本文件名

Autohotkey storing combobox variable as a text file name

首先,我能够从我计算机上的列表中创建一个组合框。然后我尝试 select 组合框中的一个项目,将其存储为一个变量,创建一个具有该变量名称的文本文件,并将剪贴板内容附加到该文件。我的脚本将执行此操作,但仅限于组合框中的最后一个 selection。我希望它适用于任何 selected 项目。请帮我。

Fileread, List, %A_ScriptDir%\My List.txt
Sort, List
Gui, Add, Button, x425 y2 w40 h30 , Write
Gui +Delimiter`n
Gui, Add, combobox, x10 y36 w500 h200 vVar, %list%
Gui, Add, Text, x10 y3 w300 h30 , Select one of  the file names from the dropdown list. Then press "Write" to paste clipboard contents to a new or existing text file.
Gui, Show, AutoSize, ASR Field Information
Return

ButtonWrite:
gui, submit, nohide
sleep 100
msgbox Text file will be named: %VAR%.txt
FILEAPPEND,
(
%clipboard%
), %A_ScriptDir%\%var%.txt
sleep 1000
run %A_ScriptDir%\var.txt
return

在我修复了一些似乎是小错误之后,您的脚本似乎可以按预期运行:

修复:

...
var := trim(var, " `t`r`n")                   ; trim trailing LF/CR
msgbox Text file will be named: %VAR%.txt
...
run %A_ScriptDir%\%var%.txt                   ; added %'s to expand var
...

我的List.txt

Alpha
Beta
Delta
Gamma

我将文本复制到剪贴板,将 AutoHotKey 重新加载到 运行 您的代码,从下拉列表中选择 "Alpha"(我文件中的第一行),然后按下写入按钮。 MsgBox 说 "Text file will be named: Alpha.txt" 然后 Alpha.txt 打开,我的剪贴板文本附加到末尾