Skip to content

Instantly share code, notes, and snippets.

@u1i
Created May 17, 2023 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1i/66ba72ddaee5ff16b529653b4738dd4c to your computer and use it in GitHub Desktop.
Save u1i/66ba72ddaee5ff16b529653b4738dd4c to your computer and use it in GitHub Desktop.
Chrome Watcher - what files does it read and write
#!/bin/bash
# Array to store the filenames from the previous loop
previous_files=()
# Infinite loop
while :
do
# Run the lsof command and filter for Google Chrome process
files=$(lsof -c "Google Chrome" | awk '{print $9}' | sed '1d')
# Loop over the filenames
while IFS= read -r filename
do
# Check if the filename is not in the previous_files array and is a file in the macOS filesystem
if [[ ! -z "$filename" ]] && [[ ! "$filename" =~ ":" ]] && [[ -e "$filename" ]] && ! [[ " ${previous_files[@]} " =~ " ${filename} " ]]; then
# Print the filename
echo "$filename"
# Add the filename to the previous_files array
previous_files+=("$filename")
fi
done <<< "$files"
# Wait for a few seconds before the next loop
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment