Jump to content
Sign in to follow this  
notbillcosby

execute a command upon termination of script?

Recommended Posts

I'm wondering if there's a way to make a script do something right before it closes... or pauses even. I've made a script that hides a certain window, and I'd like it to show the window again when the script is closed or paused. Is there a way to do it?

Share this post


Link to post
Share on other sites

This will be the function called when exit of the script, is performed. Just replace 'FuncName' with the name of the function that you choose for the task.

Opt('OnExitFunc', 'FuncName')

Func FuncName()
; Last lines of code to run.
EndFunc

:lmao:

Share this post


Link to post
Share on other sites

I had no idea that existed!

Thanks MHz :lmao:


"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

This will be the function called when exit of the script, is performed. Just replace 'FuncName' with the name of the function that you choose for the task.

Opt('OnExitFunc', 'FuncName')

Func FuncName()
; Last lines of code to run.
EndFunc

:lmao:

<{POST_SNAPBACK}>

I'm probably being both ignorant and stupid, but i'm really having a hard time understaning how this works (even after trying to read up on OnExitFunc as well as Func itself...) well enough to make my damn script work.

I'm just trying to get a damn internet explorer window, that is hidden at the beginning of the script, to unhide itself when you close the script. Upon exit, i just need it to undo this:

While 1
If WinActive("The next page will") Then WinSetState ("The next page will", "", @SW_HIDE)
;I know I'll need WEnd at the end.

Little help? Thanks...

Share this post


Link to post
Share on other sites

Opt('OnExitFunc', 'FuncName'); Place at top of script.

Func FuncName()
    If WinExists("The next page will") Then WinSetState ("The next page will", "", @SW_SHOW)
EndFunc

Give this a try. It should work, if the title is correct?

Share this post


Link to post
Share on other sites

Opt('OnExitFunc', 'FuncName'); Place at top of script.

Func FuncName()
    If WinExists("The next page will") Then WinSetState ("The next page will", "", @SW_SHOW)
EndFunc

Give this a try. It should work, if the title is correct?

<{POST_SNAPBACK}>

I think that's pretty much what I was doing... I get the same error message when i copy and paste your code as i did when I was doing it myself, so maybe it isn't just me... Here's what I have for code:

While 1 = 1

Opt('OnExitFunc', 'FuncName'); Place at top of script.

If WinActive("The next page will") Then WinSetState ("The next page will", "", @SW_HIDE)

Func FuncName()
    If WinExists("The next page will") Then WinSetState ("The next page will", "", @SW_SHOW)
EndFunc

WEnd

The error message that shows reads:

Line 7 (File "C:\ big long path\autohider.AU3"):

Func FuncName()

Error: "While" statement has no matching "Wend" statement.

I don't know why, or where, it wants another Wend statement...

Share this post


Link to post
Share on other sites

I cannot think of any reason, why you would put, any of that code within a while loop?

Especially a User Defined Function.

Share this post


Link to post
Share on other sites

Your stuff is all out of order. Try this:

Opt('OnExitFunc', 'FuncName'); Place at top of script.

While 1
     If WinActive("The next page will") Then WinSetState ("The next page will", "", @SW_HIDE)
WEnd

Func FuncName()
    If WinExists("The next page will") Then WinSetState ("The next page will", "", @SW_SHOW)
EndFunc

MHz, the reason is that he wants his script to constantly keep closing windows with that name.

Share this post


Link to post
Share on other sites

Your stuff is all out of order. Try this:

Opt('OnExitFunc', 'FuncName'); Place at top of script.

While 1
     If WinActive("The next page will") Then WinSetState ("The next page will", "", @SW_HIDE)
WEnd

Func FuncName()
    If WinExists("The next page will") Then WinSetState ("The next page will", "", @SW_SHOW)
EndFunc

MHz, the reason is that he wants his script to constantly keep closing windows with that name.

<{POST_SNAPBACK}>

That did the trick, thanks!

And yes... That's why i had the while loop.

Share this post


Link to post
Share on other sites

I'm wondering if there's a way to make a script do something right before it closes... or pauses even. I've made a script that hides a certain window, and I'd like it to show the window again when the script is closed or paused. Is there a way to do it?

<{POST_SNAPBACK}>

Func OnAutoItExit()

;say goodbye

EndFunc

no need to use Opt('OnExitFunc', 'FuncName')

Use the helpfile Luke!

Share this post


Link to post
Share on other sites

yes, but people may prefer to use Opt('OnExitFunc','FuncName')

~~~~~~~~~~~~~~~~~~~~


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...