Jump to content

Passing variables into a compiled script?


Recommended Posts

Good morning Ladies and Gentlemen,

I'm appealing to the scripting gurus out there for, (hopefully) a simple fix for my current issue.

I have a script that removes quotation marks from a text file, simple enough.

Currently, the script opens each txt file by name in order to do this, which wasn't a huge problem when I had 11 txt files, but now I'm adding ~70 more and adding a section for each by name would be quite cumbersome.

Rather, it would be more elegant to be able to pass a variable into the script so it knows the txt file to open.

What I'm hoping for:

A batch file that I can run my script from with something similar to the following line

quotes.exe pr.txt -- where quotes.exe is a compiled script that grabs pr.txt as the variable of what to open. My current attempt(which, obviously doesn't work) is below. Also, if anyone can come up with a better way to accomplish this, I'd be most grateful. A flexible script that could replace any txt with any txt would be wonderful(IE being able to pass multiple variables, txt file, txt to be replaced, replacement string) Thank you all in advance for any advice or direction :lmao:

Example of my batch file

FOR /F %%I in (cities.txt) DO CALL :_quotes %%I

GOTO :EOF

:_quotes

Echo %time% - Calling quotes.exe

start /w quotes.exe %1

GOTO :EOF

script code

; Script Function:

; Opens Notepad, removes quotes and then quits.

;

dim $txt = $CmdLine[1]

; Run Notepad

Run("notepad.exe $txt")

; Wait for the Notepad become active - it is titled "$txt.txt - Notepad" on English systems

WinWaitActive("$txt - Notepad")

; Now that the Notepad window is active replace " with (space)

Send("!e")

Sleep(50)

Send("r")

Sleep(50)

Send("+'")

Sleep(50)

Send("{TAB}{TAB}{TAB}{TAB}{TAB}")

Sleep(50)

Send("{ENTER}")

Send("{TAB}")

Sleep(50)

Send("{ENTER}")

Sleep(50)

Send("!f")

Send("x")

WinWaitActive("Notepad", "No")

Send("y")

WinWaitClose("$txt - Notepad")

Link to comment
Share on other sites

Change:

WinWaitActive("$txt - Notepad")

To:

WinWaitActive($txt & " - Notepad")

Do the same with:

WinWaitClose("$txt - Notepad")

(There are more reliable ways to use AutoIt to change a text file... but we will save that for another post.)

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Might want to look into FileReadLine(), FileWriteLine(), StringInStr(), and StringReplace().

Those will always help you greatly.

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...