Skip to content

Instantly share code, notes, and snippets.

@jxramos
Last active July 24, 2021 03:09
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 jxramos/add4da0075bb84072da57e0d85e8d9a2 to your computer and use it in GitHub Desktop.
Save jxramos/add4da0075bb84072da57e0d85e8d9a2 to your computer and use it in GitHub Desktop.
"""
Script to automate the tagging of the File Details from Windows Explorer given a folder path,
the tags to enter into the images, and the number of images to add the tags to.
"""
# BASE PYTHON
import argparse
import os
import sys
# THIRD PARTY
import pyautogui
def parse_args():
parser = argparse.ArgumentParser(description="Automates the tagging of multiple images in a folder.")
parser.add_argument("--folder", "-f", required=True, help="A directory of images to tag.")
parser.add_argument("--tags", "-t", required=True, help="The tags to apply to the images.")
parser.add_argument("--count", "-c", type=int, required=True, help="The number of images to repeat the tags with.")
parser.add_argument("--skip", "-s", type=int, default=0, help="The number of images to skip over.")
return parser.parse_args()
def main(args):
# validate folder
if not os.path.exists(args.folder):
print("ERROR path does not exist: " + args.folder)
sys.exit(0)
# Interactive Checkpoint Prompt (bail or proceed?)
proceed_prompt_msg = f"Ready to tag photos?\n tags={args.tags}\n folder={args.folder}\n count={args.count}"
button = pyautogui.confirm(proceed_prompt_msg)
if button == 'Cancel':
sys.exit(0)
# Open folder and close it to ensure starting from fresh UI state
pyautogui.hotkey('win', 'r')
pyautogui.write(args.folder, 0.001)
pyautogui.write(['enter'])
pyautogui.sleep(0.25)
pyautogui.hotkey('alt', 'f4')
# Open folder
pyautogui.hotkey('win', 'r')
pyautogui.write(args.folder, 0.001)
pyautogui.write(['enter'])
# Skip over images
for i in range(args.skip):
# next image
pyautogui.write(['right'])
# Tag each photo
for i in range(args.count):
# Select image
pyautogui.write(['space'])
# open photo properties
pyautogui.hotkey('alt', 'enter')
# navigate to details
pyautogui.hotkey('ctrl', 'tab')
pyautogui.hotkey('ctrl', 'tab')
# navigate to tags
pyautogui.write(['home', 'down', 'down', 'down'])
# write tags
pyautogui.write(args.tags, 0.01)
# save tags
pyautogui.write(['enter']*2, 0.1)
pyautogui.sleep(0.15)
# next image
pyautogui.write(['right'])
if __name__ == "__main__":
args = parse_args()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment