Jump to content

My InputBox is leaking!


Recommended Posts

G'day everyone

I'm copying my entire script because I don't know where the error lies, but check the line just after

; HERE LIES ERROR!!!

Here is my script:

; this line works with beta only
#include <File.au3>

; Exit script if user doesn't have project open:

MsgBox (1, "Confirm project is open", "Make sure the project you want to extract an untranslated TM from, is currently open in OmegaT.  If not, click Cancel.")
If @error = 2 Then Exit

; Wait until OmegaT is active:

WinActivate ("OmegaT","")
WinWaitActive ("OmegaT","")

; Open Project Properties and get path to \omegat\ folder:

Send ("^e")
Send ("{TAB 6}")
Send ("+{HOME}")
Send ("^c")
Send ("{ESC}")

$clip1 = ClipGet()

$defaultomegat = StringReplace($clip1, "\source\", "\omegat\")

; Just in case the clipboard changes in the mean time, get project name:

; $projectpath = StringTrimRight ($clip1, 8)
; $projectpath2 = StringSplit ($projectpath, "\")
; $projectname = $projectpath2[5]

$omttitle = WinGetTitle ("OmegaT", "")
$omttitle2 = StringSplit($omttitle, ":: ", 1)
$projectname = $omttitle2[2]

$projectnamereal = InputBox ("Confirm folder name", "Please confirm the name of your current project", $projectname, "", 300, 200)

; Note to self:
; Optional method to get project path (but user must still enter project name)
; in: @AppDataDir & "OmegaT\omegat.prefs"
; line 15: get <current_folder>PROJECT_PATH_IS_HERE</current_folder>

; Ask user to confirm path:

; HERE LIES ERROR!!!

$defaultomegat2 = InputBox ("Confirm \omegat\ folder location", "Please confirm the location of your \omegat\ folder", $defaultomegat, "", 500, 200)

; Get total number of segments from project_stats.txt:

$projectstats = FileOpen ($defaultomegat2 & "project_stats.txt", 0)
$projectstats2 = FileReadLine ($projectstats, 4)
$projectstats3 = StringSplit(projectstats2, @TAB)
$numofsegments = $projectstats3[3]
FileClose($projectstats)

; Ask user to confirm total number of segments in project:

$numofsegments2 = InputBox ("Confirm number of segments", "Please confirm the total number of segments in your project", $numofsegments, "", 200, 200)
$numofsegmentsplus = $numofsegments2 + 3

; Create a backup copy of user's prefs file:

FileCopy (@AppDataDir & "OmegaT\omegat.prefs", @AppDataDir & "OmegaT\omegat_prefs.rollback", 1)

; Change certain values in user's prefs file, namely:
; Tab to advance
; Copy source
; Allow to be equal
; Don't insert match

$prefsfile = FileOpen (@AppDataDir & "OmegaT\omegat.prefs", 1)
_FileWriteToLine($prefsfile, 18, "<tab_advance>true</tab_advance>", 1)
_FileWriteToLine($prefsfile, 21, "<wf_noSourceText>false</wf_noSourceText>", 1)
_FileWriteToLine($prefsfile, 22, "<wf_allowTransEqualToSrc>true</wf_allowTransEqualToSrc>", 1)
_FileWriteToLine($prefsfile, 23, "<wf_insertBestMatch>false</wf_insertBestMatch>", 1)
FileClose($prefsfile)

; Exit OmegaT and reopen it and the project in it:

WinActivate ("OmegaT","")
WinWaitActive ("OmegaT","")

Send ("^q")

If WinExists ("Confirm", "Do you really want to quit?") Then
Send ("{ENTER}")
EndIf

Run (@ProgramFilesDir & "OmegaT\OmegaT.exe")

WinActivate ("OmegaT","")
WinWaitActive ("OmegaT","")

Send ("^o")
Send $projectnamereal
Send ("{ENTER}")
Send ("{ESC}")

; Now run through all segments

WinActivate ("OmegaT","")
WinWaitActive ("OmegaT","")

Send ("{TAB" & $numofsegmentsplus & "}")

; Save the project:

Send ("^s")

; Now copy the TMX file to the desktop:

FileCopy ($defaultomegat2 & "project_save.tmx", @DesktopDir & "untranslated.tmx", 1)

; Then exit OmT again for rollback:

WinActivate ("OmegaT","")
WinWaitActive ("OmegaT","")

Send ("^q")

If WinExists ("Confirm", "Do you really want to quit?") Then
Send ("{ENTER}")
EndIf

; Then rollback:

FileDelete (@AppDataDir & "OmegaT\omegat.prefs")
FileCopy (@AppDataDir & "OmegaT\omegat_prefs.rollback", @AppDataDir & "OmegaT\omegat.prefs", 1)

MsgBox (0, "Done!", "Completed untranslated.tmx copied to your Desktop", 5)

Exit

At the error, the user is supposed to be prompted with an InputBox containing $defaultomegat (which is a path like C:\Something\Something else\), but instead, when I run the script, it seems that AutoIt thinks the entire script is $defaultomegat because it puts the entire script in the InputBox!

Any idea what I'm doing wrong?

Thanks

Samuel

PS I'm not even sure if the rest of the script works... I'm fixing errors as I encounter them.

Link to comment
Share on other sites

Working on a clipboard app and having the same problem. If you have copied a portion of your code into the clipboard using ctrl-c or just plain old copy and paste, of course it's gonna take that information and spit it back out into the inputbox cause your inputbox is going to fill in with clipget()

F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]
Link to comment
Share on other sites

If you have copied a portion of your code into the clipboard using ctrl-c or just plain old copy and paste, of course it's gonna take that information and spit it back out into the inputbox cause your inputbox is going to fill in with clipget()

Thanks for that... I realise that, but why doesn't the lines...

Send ("^e")
Send ("{TAB 6}")
Send ("+{HOME}")
Send ("^c")
Send ("{ESC}")

$clip1 = ClipGet()

...cause what is currently in the clipboard to be overwritten with the new copied contents?

The weird thing is that the script sometimes works, but sometimes misbehaves, depending on various things I change in the script.

Link to comment
Share on other sites

Just a quick thought, is the text you are copying to clipboard highlighted when you send Send ("^c") ? also Some sleeps between steps may help.

Yes it is. I have since done something which seems to work (although I haven't tested it thoroughly), namely that in the original script the text to be copied was highlighted from right to left, which I then changed so that it highlights from left to right. That seems to work (or: it seems to work better).

I.e. instead of

Send ("+{HOME}")
Send ("^c")

rather use:

Send ("{HOME}")
Send ("+{END}")
Send ("^c")
Link to comment
Share on other sites

If you wouldn't mind taking it a little bit further I would recommend you to read about

ControlSend. I've never liked the use of Send, at least when it can be avoided with

much better alternatives. Read about the Control* functions and I'm sure you'll be able

to create a much more stable script. Good luck !

Link to comment
Share on other sites

If you wouldn't mind taking it a little bit further I would recommend you to read about

ControlSend.

Thanks, but many Java programs (including this one, and also OpenOffice in fact) doesn't have named controls. Very, very annoying.

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...