Jump to content

Show HDD's Free Space + Notfiy when Low


 Share

Recommended Posts

I'm trying to figure out how to loop this little script, so that it shows the amount of the HDD's space left in real time. And also to run an external program (that will notify me in several ways) when the HDD's space becomes too low, for example when there's only 10 GB left.

Here's a little script i just compiled, right now it just shows the space left on Drive C:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

$Free = DriveSpaceFree("C:\")
$Free = $Free / 1024
$Free = Round($Free,1)

$hGUI = GUICreate("", 60, 15, -1, -1, $WS_POPUP)
GUISetBkColor(0x000000, $hGUI)

$OutputText = GUICtrlCreateLabel($Free & " GB", -1, 0)
GUICtrlSetColor($OutputText, 0xFFFFFFF)

GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

I tried to loop it with the (While 1 / WEnd) function, it loops but it runs the script with multiple instances.

It would be also great if this script only shows up on the tray notification area and not on the taskbar.

Edited by ManualIT
Link to comment
Share on other sites

@ManualIT
Maybe something like this? :)

#include <TrayConstants.au3>

; This will allow you to click on the TrayIcon without pause the script
Opt("TrayAutoPause", 0)

ManageTrayIcon()

Func ManageTrayIcon()

    TrayItemSetText($TRAY_ITEM_PAUSE, "Pause Script")
    TrayItemSetText($TRAY_ITEM_EXIT, "Exit Script")

    Local $strDrive = "C:\", _
          $fltDriveFreeSpace = GetDriveFreeSpace($strDrive), _
          $fltDriveLowSpace = 10.0 ; GB

    TraySetState($TRAY_ICONSTATE_SHOW)
    TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")

    While 1
        $fltDriveFreeSpace = GetDriveFreeSpace($strDrive)
        If $fltDriveFreeSpace <= $fltDriveLowSpace Then
            TraySetState($TRAY_ICONSTATE_FLASH)
            TraySetToolTip("Low free space on'" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")
        Else
            TraySetState($TRAY_ICONSTATE_STOPFLASH)
            TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")
        EndIf

        Sleep(100)
    WEnd

EndFunc

Func GetDriveFreeSpace($strDrive)
    Return Round((DriveSpaceFree($strDrive)/1024), 1)
EndFunc

 

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@FrancescoDiMuro

Thank you so much!

This script works with no problems, however, i'd rather have it show a GUI on my desktop, you know like a widget, similar to the GUI of my script.

And if it gets low, it runs an external program.

And what i meant about this post:

Quote

It would be also great if this script only shows up on the tray notification area and not on the taskbar.

Is i just don't want this script (while it is running) to show on the taskbar, just on the tray, so if i want to close/exit the script i can do so from the tray

But still, your script is very useful, i really appreciate it!

 

 

Edited by ManualIT
Link to comment
Share on other sites

3 minutes ago, ManualIT said:

This script works with no problems, however, i'd rather have it show a GUI on my desktop, you know like a widget, similar to the GUI of my script.

Then it's what you've already done :)
Just modify the part where you display the free space, and, analyizing it, when it goes lower or equale than the "low limit", call whatever you want.
Happy to have helped ;)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

1 hour ago, FrancescoDiMuro said:

Then it's what you've already done :)
Just modify the part where you display the free space, and, analyizing it, when it goes lower or equale than the "low limit", call whatever you want.
Happy to have helped ;)

 

Actually i think it would be great using both Tray and GUI, so right now i'm trying to modify your script.

 

I added this part:

 

$hGUI = GUICreate("", 60, 15, -1, -1, $WS_POPUP)
            GUISetBkColor(0x000000, $hGUI)
            $OutputText = GUICtrlCreateLabel($fltDriveFreeSpace & " GB", -1, 0)
            GUICtrlSetColor($OutputText, 0xFFFFFFF)
            GUISetState()
            Do
            Until GUIGetMsg() = $GUI_EVENT_CLOSE

 

Right after this part:

 

TraySetState($TRAY_ICONSTATE_STOPFLASH)
TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")

 

GUI Shows but it doesn't update the free space

 

#include <TrayConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>

; This will allow you to click on the TrayIcon without pause the script
Opt("TrayAutoPause", 0)

ManageTrayIcon()

Func ManageTrayIcon()

    TrayItemSetText($TRAY_ITEM_PAUSE, "Pause Script")
    TrayItemSetText($TRAY_ITEM_EXIT, "Exit Script")

    Local $strDrive = "C:\", _
          $fltDriveFreeSpace = GetDriveFreeSpace($strDrive), _
          $fltDriveLowSpace = 10.0 ; GB

    TraySetState($TRAY_ICONSTATE_SHOW)
    TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")

    While 1
        $fltDriveFreeSpace = GetDriveFreeSpace($strDrive)
        If $fltDriveFreeSpace <= $fltDriveLowSpace Then
            TraySetState($TRAY_ICONSTATE_FLASH)
            TraySetToolTip("Low free space on'" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")
         Else
            TraySetState($TRAY_ICONSTATE_STOPFLASH)
            TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")
            $hGUI = GUICreate("", 60, 15, -1, -1, $WS_POPUP)
            GUISetBkColor(0x000000, $hGUI)
            $OutputText = GUICtrlCreateLabel($fltDriveFreeSpace & " GB", -1, 0)
            GUICtrlSetColor($OutputText, 0xFFFFFFF)
            GUISetState()
            Do
            Until GUIGetMsg() = $GUI_EVENT_CLOSE
        EndIf

        Sleep(100)
    WEnd

EndFunc

Func GetDriveFreeSpace($strDrive)
    Return Round((DriveSpaceFree($strDrive)/1024), 2)
EndFunc

 

Edited by ManualIT
Link to comment
Share on other sites

            Do
            Until GUIGetMsg() = $GUI_EVENT_CLOSE

What is this ?

L**p ?

 

How do you expect to do somthing if you do not exit from that ?

 

Try : 

While (1) 
...;Your begining code
$msg = GUIGetMsg ()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
...;Your ending code
WEnd

Edit: Oups forgot:  EndSwitch

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

@user4157124 

I prefer learn him how to manage Case. In case he got more complicated Gui.

 

This will generate less demand, if the person learn a complicated thing that she can simplify. The opposite will make a further question. 

B)

 

Who's dev and is'n lazy ? hihi

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
Share on other sites

  • Moderators
1 hour ago, caramen said:

Who's dev and is'n lazy ? hihi

This was unnecessary. Unless a suggestion from another forum member makes absolutely no sense for the OP's use (as some of yours have during your time here), which is not the case with user4157124's post, and there is no true performance benefit to doing it one way or another other than your personal preference, how about keeping your opinions to yourself? 

"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

I managed to get it to work, with having both GUI and Tray Notifications, still working on the GUI design.

 

#include <TrayConstants.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>


GUICreate("", 100, 100,1200, 650,$WS_POPUP)
GUISetBkColor(0x000000, "")
GUISetState(@SW_SHOW)

Opt("TrayAutoPause", 0)

ManageTrayIcon()

Func ManageTrayIcon()

    TrayItemSetText($TRAY_ITEM_PAUSE, "Pause Script")
    TrayItemSetText($TRAY_ITEM_EXIT, "Exit Script")

    Local $strDrive = "C:\", _
          $fltDriveFreeSpace = GetDriveFreeSpace($strDrive), _
          $fltDriveLowSpace = 10.0 ; GB

    TraySetState($TRAY_ICONSTATE_SHOW)
    TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")

    While 1
        $fltDriveFreeSpace = GetDriveFreeSpace($strDrive)
        If $fltDriveFreeSpace <= $fltDriveLowSpace Then
$Low = GUICtrlCreateLabel($fltDriveFreeSpace,1,1)
GUICtrlSetColor ($Low, $COLOR_RED )
GUICtrlSetFont($Low, 10, 600)

            TraySetState($TRAY_ICONSTATE_FLASH)
            TraySetToolTip("Low free space on'" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")
         Else

$Normal = GUICtrlCreateLabel($fltDriveFreeSpace,1,1)
GUICtrlSetColor ($Normal, $COLOR_GREEN )
GUICtrlSetFont($Normal, 10, 600)

Sleep(2000)
            TraySetState($TRAY_ICONSTATE_STOPFLASH)
            TraySetToolTip("Free space on '" & $strDrive & "' : " & $fltDriveFreeSpace & " GB")
        EndIf
        Sleep(100)
    WEnd

EndFunc

Func GetDriveFreeSpace($strDrive)
    Return Round((DriveSpaceFree($strDrive)/1024), 2)
EndFunc

 

Just a couple of things to add and i'm all set:

- I want the script to run a program when the space becomes low
- I don't want the script to be shown on the taskbar at all if possible.

 

 

Edited by ManualIT
Link to comment
Share on other sites

7 minutes ago, ManualIT said:

- I want the script to run a program when the space becomes low

In the If...Else...EndIf statement, set a ShellExecute(), Run*, or call another function in your script.

8 minutes ago, ManualIT said:

- I don't want the script to be shown on the taskbar at all if possible.

Maybe this could help you :)
 

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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