Jump to content
Sign in to follow this  
Diana (Cda)

How to close this script?

Recommended Posts

Diana (Cda)

I'm only having problem with one aspect of a script. Here is the script in question:

;
; AutoIt 3x
;
#include <GuiConstants.au3>
#include <_PartitionLetters.au3>     ; this replaces drive letters
#include<_WEReplacement.au3>     ; references a Windows Explorer replacement program
#Include<_SYSTRAY, refresh.au3>
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon($Icons1 & "\TXT file icon 01.ico")



#region ===== File: ===================================================
$File = @ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt"
#endregion ============================================================



;*****===== Tray "context menu": =====*****=====*****=====*****=====*****=====
;Opt("GuiOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
;------------------------------------------------------------------------------
TrayCreateItem($File)
    TrayItemSetOnEvent(-1, "_UnhideWindow")
TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "_Quit")
TrayCreateItem("")     ; creates a "separator" line between  items in tray menu
;*****=====*****=====*****=====*****=====*****=====*****=====*****=====*****=====

;--------------
While 1
    Sleep(150)
WEnd
;--------------




ShellExecute($File, "", "", "Open", @SW_HIDE)


Func _UnhideWindow()
    ShellExecute($File, "", "", "Open", @SW_SHOW)
    ; CLOSE SCRIPT AND REMOVE FROM TRAY ... ?
EndFunc

Func _Quit()
    Exit
EndFunc   ;==>_Quit

There might not be a simple way to minimize to tray but fortunately I learned how to work with tray scripting just recently and thought the @SW_HIDE might just work after all. I've managed so far to mimic opening something and sending directly to the tray. The only part I can't figure out is where it says above "CLOSE SCRIPT AND REMOVE FROM TRAY ...". Right now, when this script is running, the process shows up merely as the usu. "Autoit.exe". For obvious reasons,

ProcessClose("AutoIt3.exe")

just would not be a good thing to use.

Is there a way to get this script to close when clicking on "Exit" in the tray (its name is "PUAC- LaunchIfNotRunning - DO NOT RUN APPS.au3")? It's not using the process name or whether or not a file exists, so I just don't have a notion what coding to use.

Thanks! :mellow:

Share this post


Link to post
Share on other sites
Diana (Cda)

Actually, instead of right-clicking on an AI script tray item, is there code to handle a double-click instead? That would mimic the whole tray thing completely of opening a tray-minimized script.

Share this post


Link to post
Share on other sites
ludocus

your doing it wrong..

use:

;
; AutoIt 3x
;
Opt('WinTitleMatchMode', 2')
#include <GuiConstants.au3>
#include <_PartitionLetters.au3>    ; this replaces drive letters
#include<_WEReplacement.au3>    ; references a Windows Explorer replacement program
#Include<_SYSTRAY, refresh.au3>
#NoTrayIcon ; AutoIt's icon doesn't show in systray
TraySetIcon($Icons1 & "\TXT file icon 01.ico")



#region ===== File: ===================================================
$File = @ScriptDir & "\PUAC- LaunchIfNotRunning - DO NOT RUN APPS.txt"
#endregion ============================================================



;*****===== Tray "context menu": =====*****=====*****=====*****=====*****=====
;Opt("GuiOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
;------------------------------------------------------------------------------
$item = TrayCreateItem($File)
    TrayItemSetOnEvent(-1, "_UnhideWindow")
TrayCreateItem("")  ; creates a "separator" line between  items in tray menu
    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "_Quit")
TrayCreateItem("")  ; creates a "separator" line between  items in tray menu
;*****=====*****=====*****=====*****=====*****=====*****=====*****=====*****=====

;--------------
While 1
    Sleep(150)
WEnd
;--------------




ShellExecute($File, "", "", "Open", @SW_HIDE)


Func _UnhideWindow()
  ;WinSetState('LaunchIfNotRunning - DO NOT RUN APPS', '', @SW_SHOW) If you want to show it
   WinClose('LaunchIfNotRunning - DO NOT RUN APPS');to close the window..
   TrayItemDelete($item);to delete the item
  ;ShellExecute($File, "", "", "Open", @SW_SHOW) <== WRONG
  ; CLOSE SCRIPT AND REMOVE FROM TRAY ... ?
EndFunc

Func _Quit()
    Exit
EndFunc  ;==>_Quit
Edited by ludocus

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.