Jump to content

Quick launch tool (directory)


Recommended Posts

Hi Guys,

I've been searching for a few days and did not find anything that can help me.

I have a small and simple script that lists all executable s in a directory, my problem is to get them to run.

The main challenge is that the directory is dynamic (the number of apps varies).

Right now I have to see if there are any changes in the folder and fix the WHILE section to reflect the correct numbers of apps.

Thanks for you time.

#include <Array.au3>
#include <RecFileListToArray.au3>

Opt("TrayMenuMode", 3)

Global $Path = @ProgramFilesDir & "\ITAM - Report"
Global $aArray = _RecFileListToArray($Path, "*.exe", 1)
Global $Total = _ArrayMax($aArray)

For $i = 1 To $Total
TrayCreateItem($i & '- ' & StringTrimRight($aArray[$i], 4))
Next
TrayCreateItem("")
$Quit = TrayCreateItem("Exit")

TraySetState(4)
TrayTip("ITAM - Quick launch", "You can access the tools by clicking on this icon", 5, 1)
TraySetState(16)
TraySetToolTip('ITAM - Quick launch')
While 1
$Msg = TrayGetMsg()
Select
Case $Msg = 7
Run('"' & $Path & '\' & $aArray[1] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 8
Run('"' & $Path & '\' & $aArray[2] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 9
Run('"' & $Path & '\' & $aArray[3] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 10
Run('"' & $Path & '\' & $aArray[4] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 11
Run('"' & $Path & '\' & $aArray[5] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 12
Run('"' & $Path & '\' & $aArray[6] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 13
Run('"' & $Path & '\' & $aArray[7] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 14
Run('"' & $Path & '\' & $aArray[8] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = $Quit
Exit 0
EndSelect
WEnd
Link to comment
Share on other sites

Reread the help file for what ArrayMax does, because you're using it wrong.

You want Ubound.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

Re-read the OP; he doesn't want to just execute them all. He is creating a tool tray so he can click on the one he wants to run. As BrewManNH mentions, he need to use Ubound with the array to make it dynamic.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Maybe something like this?

#include <Array.au3>
#include <RecFileListToArray.au3>

Opt("TrayMenuMode", 3)

Global $Path = @ProgramFilesDir & "\ITAM - Report"
Global $aArray = _RecFileListToArray($Path, "*.exe", 1)
Global $Total = Ubound($aArray) - 1 
; or you can use this
;~ Global $Total = $aArray[0]
;~ Either of these will give the same result


For $i = 1 To $Total
     TrayCreateItem($i & '- ' & StringTrimRight($aArray[$i], 4))
Next
TrayCreateItem("")
$Quit = TrayCreateItem("Exit")

TraySetState(4)
TrayTip("ITAM - Quick launch", "You can access the tools by clicking on this icon", 5, 1)
TraySetState(16)
TraySetToolTip('ITAM - Quick launch')
While 1
     $Msg = TrayGetMsg()
     Select
          Case $Msg = 7
               Run('"' & $Path & '\' & $aArray[1] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 8
               Run('"' & $Path & '\' & $aArray[2] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 9
               Run('"' & $Path & '\' & $aArray[3] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 10
               Run('"' & $Path & '\' & $aArray[4] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 11
               Run('"' & $Path & '\' & $aArray[5] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 12
               Run('"' & $Path & '\' & $aArray[6] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 13
               Run('"' & $Path & '\' & $aArray[7] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = 14
               Run('"' & $Path & '\' & $aArray[8] & '"', @ScriptDir, @SW_SHOW)
          Case $Msg = $Quit
               Exit 0
     EndSelect
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Maybe something like this?

#include <Array.au3>
#include <RecFileListToArray.au3>

Opt("TrayMenuMode", 3)

Global $Path = @ProgramFilesDir & "\ITAM - Report"
Global $aArray = _RecFileListToArray($Path, "*.exe", 1)
Global $Total = Ubound($aArray) - 1
; or you can use this
;~ Global $Total = $aArray[0]
;~ Either of these will give the same result


For $i = 1 To $Total
TrayCreateItem($i & '- ' & StringTrimRight($aArray[$i], 4))
Next
TrayCreateItem("")
$Quit = TrayCreateItem("Exit")

TraySetState(4)
TrayTip("ITAM - Quick launch", "You can access the tools by clicking on this icon", 5, 1)
TraySetState(16)
TraySetToolTip('ITAM - Quick launch')
While 1
$Msg = TrayGetMsg()
Select
Case $Msg = 7
Run('"' & $Path & '\' & $aArray[1] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 8
Run('"' & $Path & '\' & $aArray[2] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 9
Run('"' & $Path & '\' & $aArray[3] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 10
Run('"' & $Path & '\' & $aArray[4] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 11
Run('"' & $Path & '\' & $aArray[5] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 12
Run('"' & $Path & '\' & $aArray[6] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 13
Run('"' & $Path & '\' & $aArray[7] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = 14
Run('"' & $Path & '\' & $aArray[8] & '"', @ScriptDir, @SW_SHOW)
Case $Msg = $Quit
Exit 0
EndSelect
WEnd

Hi BrewManNH,

Thanks for you reply but that does exactly the same thing as my original script. I think that I wasn't clear enough. I would like to automate the WHILE section as the quantities of executables will vary and I don't want to edit my script every time that there is a change in the directory. Therefore I need to find away to have a variable in the WHILE that will run the proper script only when clicked.

This is what I had tried but it doesn't work as it launches all the apps.

While 1

$Msg = TrayGetMsg()

Select
Case $Msg > 6
For $i = 1 To $Total
For $c = 0 To UBound($Total) ; If cliecked then run
Run('"' & $Path & '\' & $aArray[$i] & '"', @ScriptDir, @SW_SHOW)
Next
Next
Case $Msg = $Quit
Exit 0
EndSelect

WEnd

Cheers

Link to comment
Share on other sites

Hi,

I found the way to do it, thanks for all your help. Here's the code if anyone is interested:

#include <Array.au3>
#include <RecFileListToArray.au3>

Opt("TrayMenuMode", 3)

Global $Path = @ProgramFilesDir & "\ITAM - Report"

Global $aArray = _RecFileListToArray($Path, "*.exe", 1)

Global $Total = UBound($aArray) - 1
Global $Width = (36 * $Total) + 1
Global $i, $Final, $sTotal


For $i = 1 To $Total
    TrayCreateItem($i & '- ' & StringTrimRight($aArray[$i], 4))
Next
TrayCreateItem("")
$Quit = TrayCreateItem("Exit")

TraySetState(4)
TrayTip("ITAM - Quick launch", "You can access the tools by clicking on this icon", 5, 1)
TraySetState(16)
TraySetToolTip('ITAM - Quick launch')


While 1

    $Msg = TrayGetMsg()

    Select
        Case $Msg > 6 And $Msg < $Total + 8
            Run('"' & $Path & '\' & $aArray[$Msg - 6] & '"', @ScriptDir, @SW_SHOW)

        Case $Msg = $Quit
            Exit 0
    EndSelect

WEnd
Edited by CoolDude69
Link to comment
Share on other sites

Just as an FYI, if you ever have to expand this script, those numbers for the tray items probably will change. You shouldn't hard code control ids in your script if you can avoid it, and in this case you can.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Just as an FYI, if you ever have to expand this script, those numbers for the tray items probably will change. You shouldn't hard code control ids in your script if you can avoid it, and in this case you can.

Thanks for your feedback.

I know they will change but this is the only way I found that works, I have tested by adding and removing files and it works the way it's suppose to. For some reason the Tray starts at 7 that why I put > 6 and < $Total + 8 as the $Total will change with the quantity of files.

Cheers

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