Skip to content

haobecca/ScreencapCleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Automated Screen Shot Clean-Up

Objective

Write a python script to move screenshots to trash every once they are older than 24 hours.

Design

  1. Identify screenshots among other files.
  2. Identify timestamp on screenshot.
  3. Move files that are older than 24 hours to ~/.Trash.
  4. Run script periodically to ensure desktop stays tidy.

Tools Used

Python

From Python's standard library, the following objects and relevant class methods were used.

  • datetime for timestamps and datetime objects.
  • os for simplified OS-independent functionality . Notable module functions used include:
    • os.listdir(path='.'): returns a list containing the names of the entries in the directory given by path.

    • os.path.expanduser(path): expands ~ and ~user. If user or $HOME is unknown, do nothing.

    • os.stat(path, *): gets the status of a file or a file descriptor, including creation time attribute in seconds UTC (shown below).

      >>> import os
      >>> statinfo = os.stat('somefile.txt')
      >>> statinfo.st_ctime
      23452345234.4324  # seconds UTC
    • shutil.move(src, dst): recursively move a file or directory (src) to (dst) and return the destination.

    • os.path.join(a, *p): joins two or more paths, inserting '/' as needed.

Operating System (MacOS)

The shebang instructs the user's shell (e.g. bash) where to find the necessary interpreter for script. It's placed in the first line like so:

#!/usr/bin/env python3
''' My Python Script '''

# ...rest of script...

MacOS has its own framework for managing system and user-level recurring background processes (daemons) called launchd. This tool runs successfully with user-level permissions via a simple .plist file and enabled via Apple's complementary command-line launchctl tool.

References

  • Using launchd agents to schedule scripts on macOS link

About

Python script to periodically remove unneeded screenshots from the desktop.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages