Jump to content

Recommended Posts

Posted (edited)

Hi guys, this is my script:

$File1 = @WorkingDir & "\Test1.txt"
$File2 = @WorkingDir & "\Test2.txt"
$FileNameEstension = StringTrimLeft($File2, StringInStr($File2, "\", 0, -1))
$FileNameOnly = StringTrimRight($FileNameEstension, 4)
ClipPut(FileRead($File1))
Start($File2)
func Start($File2)
    If Not FileExists($File2) Then Return 0
    Return Run(@ComSpec & " /c " & "start " & FileGetShortName($File2),"",@SW_HIDE)
endfunc
If WinActive($FileNameOnly & " - Notepad") Then Send("^v")
Send("^s")
WinClose($FileNameOnly & " - Notepad")

First, would know if you can merge this part into a single string:

$FileNameEstension = StringTrimLeft($File2, StringInStr($File2, "\", 0, -1))
$FileNameOnly = StringTrimRight($FileNameEstension, 4)

The first line give me Test.txt, the second remove the extension. I try to connect with "&" but not work.

The script don't work becouse don't recognize the window name:

WinActive($FileNameOnly & " - Notepad")

I don't know what is the problem. Thanks for support :)

Edited by johnmcloud
Posted (edited)

  Quote

First, would know if you can merge this part into a single string:

Use this instead, to get just the filename.

ConsoleWrite(StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') & @LF) ; By MrCreatoR - http://www.autoitscript.com/forum/topic/41897-pathsplitbyregexp/

Try this.

WinActive("[CLASS:Notepad]"")
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

It's a nice little UDF he created, plus I'm in the midst of perfecting my knowledge of SREs so this is a great foundation to learn from.

Edit: Spelling mistake.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 12/17/2011 at 10:57 AM, 'guinness said:

Use this instead, to get just the filename.

ConsoleWrite(StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') & @LF) ; By MrCreatoR - http://www.autoitscript.com/forum/topic/41897-pathsplitbyregexp/

Not work for me ;)

$var = ConsoleWrite(StringRegExpReplace(@WorkingDir & "Test.txt", '.*|.[^.]*$', '') & @LF)
MsgBox(0,0,$var)

The result is 5 :)

Posted (edited)

Please look at the Help file to see what ConsoleWrite is, the actual code is inside the ConsoleWrite syntax see...

StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') ; By MrCreatoR
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

  On 12/17/2011 at 1:32 PM, 'guinness said:

Please look at the Help file to see what ConsoleWrite is, the actual code is inside the ConsoleWrite syntax see...

StringRegExpReplace(@ScriptFullPath, '.*|.[^.]*$', '') ; By MrCreatoR

Sorry, i'm never used ConsolWrite, but i have another problem.

Send("^v")

Seems not work, but if i click manually control+V it past:

$File1 = @WorkingDir & "Test1.txt"
$File2 = @WorkingDir & "Test2.txt"
ClipPut(FileRead($File1))
Start($File2)
func Start($File2)
    If Not FileExists($File2) Then Return 0
    Return Run(@ComSpec & " /c " & "start " & FileGetShortName($File2),"",@SW_HIDE)
endfunc
If WinActive("[CLASS:Notepad]") Then Sleep(500)
Send("^v")
Send("^s")
WinClose("[CLASS:Notepad]")

Thanks guinness for your help

Edited by johnmcloud
Posted

ControlSend perhaps?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 12/17/2011 at 1:53 PM, 'guinness said:

ControlSend perhaps?

The problem wasn't send command, but WinActive:

$File1 = @WorkingDir & "Test1.txt"
$File2 = @WorkingDir & "Test2.txt"
ClipPut(FileRead($File1))
Start($File2)
func Start($File2)
    If Not FileExists($File2) Then Return 0
    Return Run(@ComSpec & " /c " & "start " & FileGetShortName($File2),"",@SW_HIDE)
endfunc
If WinWaitActive("[CLASS:Notepad]") then Send("^v")
Send("+{F12}")
;SHIFT + F12 for save
WinClose("[CLASS:Notepad]")

I'll change with WinWaitActive, now working file. I try tu use the name of notepad windows, but don't accept it. but cherish the script for future events.

Thanks all :)

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
×
×
  • Create New...