Cookie Monitor Script

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Cookie Monitor Script

Post by Marcus Tettmar » Fri May 18, 2007 12:58 pm

Cookie Monitor Script

A winning entry to the Scripts & Tips 10 Year Anniversary Competition.
Submitted by: Robert White (thaumaturgy)

Code: Select all

#####################################################################
##
## Script Title: Cookie Monitor
## Script Year: 2007
## Script Author: [Robert White]
## Script Version: 1.0
## Operating System: Windows XP
## Script Description: This script displays all cookies located
## 		  			   in your cookies directory and tracks and
##					   logs which cookies have been updated or
##					   added, including the file time when they
##					   were added or updated. There are options
##					   to delete a single cookie, delete ALL the
##					   cookies, open the cookies directory or open
##					   a selected cookie.
## Author Notes: No additional editing needed
##
#####################################################################

//Set the application title if script is compiled
Let>APP_TITLE=Cookie Monitor

//Locate Cookie directory by reading the registry Cookies key
RegistryReadKey>HKEY_CURRENT_USER,Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders,Cookies,cookie_directory

//Remove quotation marks
StringReplace>cookie_directory,",,cookie_directory

//Get all cookies in cookies directory
GetFileList>%cookie_directory%\*.txt,cookies
GetFileList>%cookie_directory%\*.txt,check

//Get total number of cookies in cookie directory to display in dialog
Separate>check,;,check

//Remove semicolon
StringReplace>cookies,;,%CRLF%,cookies

//Remove directory path
StringReplace>cookies,%cookie_directory%\,,cookies

Dialog>Dialog1
   Caption=Cookie Monitor
   Width=503
   Height=512
   Top=0
   Left=0
   ListBox=msListBox1,8,56,225,385,%cookies%
   Button=DELETE SELECTED COOKIE,8,8,225,41,1
   Label=Total Number of Cookies: %check_count%,8,448,true
   Button=OPEN COOKIES FOLDER,240,104,241,41,3
   Button=OPEN SELECTED COOKIE,240,56,241,41,4
   Button=DELETE ALL COOKIES,240,8,241,41,5
   Label=Recently added or modified cookies.%CRLF%List updated [NEVER],240,176,true
   Memo=msMemo1,240,208,241,233,
   CheckBox=msCheckBox1,Notify me if cookies are added or updated,240,152,241,False
EndDialog>Dialog1

Show>Dialog1

Label>Main

//Set date and time for check if cookies were added or updated to display in log list msMemo1
Year>YEAR
Month>MON
Day>DAY
Hour>HHH
Min>MMM
Sec>SSS

//Get names of cookies to display in msListBox1
GetFileList>%cookie_directory%\*.txt,cookies

//Remove semicolon
StringReplace>cookies,;,%CRLF%,cookies

//Remove directory path
StringReplace>cookies,%cookie_directory%\,,cookies
Let>Dialog1.msListBox1.ITEMS.text=%cookies%
ResetDialogAction>Dialog1

//Set GetFileList to most current list of cookies. This is needed for msMemo1
GetFileList>%cookie_directory%\*.txt,check1
Separate>check1,;,check1

//Counter when to check if cookies were added or updated (300 = around 15 sec)
Let>check_counter=300
Label>MainLoop
Wait>.05
GetDialogAction>Dialog1,DialogResult
IF>DialogResult=1,DeleteSelected
IF>DialogResult=2,Exit
IF>DialogResult=3,OpenCookiesFolder
IF>DialogResult=4,OpenCookie
IF>DialogResult=5,DeleteAllCookies

//Subtract 1 from the "check_counter"
Sub>check_counter,1

//When "check_counter" reaches 0 check if cookies were added or updated
//(for displaying in log field msMemo1)
IF>check_counter=0,CheckIfAddedOrUpdated

//Set get file list to "check2".
GetFileList>%cookie_directory%\*.txt,check2

//Remove semicolon
Separate>check2,;,check2

///If GetFileList "check2" doesn't equal GetFileList "check1"
//update msListBox1 the latest cookies in the cookie directory
IF>check2<>%check1%
   //Reset GetFileList to most current list of cookies
   GetFileList>%cookie_directory%\*.txt,check1
   Separate>check1,;,check1

   //Get all cookies in cookies directory
   GetFileList>%cookie_directory%\*.txt,cookies

   //Remove semicolon
   StringReplace>cookies,;,%CRLF%,cookies

   //Remove directory path
   StringReplace>cookies,%cookie_directory%\,,cookies

   //Display all cookies in msListBox1
   Let>Dialog1.msListBox1.ITEMS.text=%cookies%

   //Display Total number of cookies displayed below msListBox1
   Let>Dialog1.msLabel2=Total Number of Cookies: %check1_count%
   ResetDialogAction>Dialog1
EndIf
Goto>MainLoop

//Delete cookie selected in msListBox1
Label>DeleteSelected
DeleteFile>%cookie_directory%\%Dialog1.msListBox1%

//Update cookie total displayed below msListBox1
GetFileList>%cookie_directory%\*.txt,check1
Separate>check1,;,check1
Let>Dialog1.msLabel2=Total Number of Cookies: %check1_count%
Goto>Main

//Open Cookies folder
Label>OpenCookiesFolder
ExecuteFile>%cookie_directory%
Goto>Main

//Open selected cookie
Label>OpenCookie
ExecuteFile>%cookie_directory%\%Dialog1.msListBox1%
Goto>Main

//Delete ALL the cookies in cookies folder
Label>DeleteAllCookies
DeleteFile>%cookie_directory%\*.txt

//Update cookie total displayed below msListBox1
GetFileList>%cookie_directory%\*.txt,check1
Separate>check1,;,check1
Let>Dialog1.msLabel2=Total Number of Cookies: %check1_count%
Goto>Main

Label>CheckIfAddedOrUpdated

//Get all cookies in cookies directory
GetFileList>%cookie_directory%\*.txt,cookies
Separate>cookies,;,cookie_names
Let>repeat_k=0
Repeat>repeat_k
   Let>repeat_k=repeat_k+1

   //Get time cookie was updated or added
   FileTime>cookie_names_%repeat_k%,MyFileTime

   //Get date cookie was updated or added
   FileDate>cookie_names_%repeat_k%,MyFileDate

   //If cookie file time is greater than the time set after "label>main" continue to check the date
   IF>MyFileTime>%HHH%%MMM%%SSS%
      //Check if date is today's date to ensure only the latest updated or added cookies get display on log msMemo1
      IF>MyFileDate=%YEAR%%MON%%DAY%
         Let>updatedCookies=cookie_names_%repeat_k%
         StringReplace>updatedCookies,%cookie_directory%\,,updatedCookies
         GetTime>time_

         //Display time log list msMemo1 was updated
         Let>Dialog1.msLabel6=Recently added or modified cookies.%CRLF%List updated @ %time_%

         //Display Cookie names and the time they were added or updated in log list msMemo1
         Let>Dialog1.msMemo1=%MyFileTime%: %updatedCookies%%CRLF%%Dialog1.msMemo1%

         //If msCheckBox1 True play Wav file if cookie(s) added to log list msMemo1
         IF>Dialog1.msCheckBox1=True
            PlayWav>%WIN_DIR%\media\chimes.wav
         EndIf
      EndIf
   EndIf
   //repeat until cookie names count reached
Until>repeat_k,cookie_names_count

//Go back to label>main
Goto>Main

Label>Exit

DAYIII
Newbie
Posts: 9
Joined: Tue May 09, 2017 2:54 am
Location: Atlanta, GA and Orem, UT

Re: Cookie Monitor Script

Post by DAYIII » Sat Jul 13, 2024 8:48 pm

This is an outstanding Tool and fine example of how to use Macro Scheduler. Thanks!
Is there an updated version of this for Chrome? I'm trying to learn more about cookies; how to read, edit or remove them.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts