Last active
May 5, 2024 00:42
-
-
Save edenwaith/684c400da9b6f5ab1983a0ab0d807700 to your computer and use it in GitHub Desktop.
Folder Action script to unarchive and move a zip file downloaded from a specific website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Script for an Automator Folder Action to check if a downloaded zip file came from a particular website | |
# (in this case, from https://gale.udemy.com), then unzip the contents to a specific location and then | |
# move the zip file also to that same destination. | |
# Set this as a Run Shell Script in Automator, and set the "Pass input:" option "as arguments" | |
for f in "$@"; do | |
# Example response from the mdls call | |
# kMDItemWhereFroms = ( | |
# "https://att-c.udemycdn.com/2023-04-13_10-05-58-56f38da77018db82042a9a9ae9fd7b77/original.zip?response-content-disposition=attachment%3B+filename%3D9.0%2BDisplay%2BFlex.zip&Expires=1714526174&Signature=3-tMr~b-Oczk0h27K4acbpMcYOgEBqzHmt2Q0XrxyhAzkEkVxplfY4Z77-xSEBJCfY8yPWH11TVgxm-cCum0LB8AP-KGA6Oy0mJArKZeF20tIDs1p3pRfd~b6p0zi5CktQp859yn9ui-jWjXUf9VPc1p67Ecqd1Dj5ow-n6Wp-UdV5C5Tz0JHdcoRKM1JeF7-JLkV79nx1YfF~K2pFfv3YOm13oMibu1q2UenE8WU5FIRbEbiIu0HEEMOXv9q4lIuPgH2ptgpB1fO6RYXXWpWhLnkQoE-cA0gWgXgG7S5rfWpPs4hTUqQbTbBTgTocaafqhOLDsD6u7~UMkgrGuuSw__&Key-Pair-Id=K3MG148K9RIRF4", | |
# "https://gale.udemy.com/" | |
# ) | |
# Check if the file was downloaded from the gale.udemy.com website | |
if [[ $(mdls -name kMDItemWhereFroms "$f") == *"https://gale.udemy.com"* ]]; then | |
dst_dir=~/Sites/the-complete-web-development-bootcamp/ | |
# unzip the file into the destination folder (dst_dir) | |
# Add the quotes around dst_dir and f, in case there are any spaces | |
unzip -d "$dst_dir" "$f" | |
# Move the file to the ~/Sites/the-complete-web-development-bootcamp/ folder | |
# (and force it, in case a file by the same name already exists there) | |
mv -fv "$f" $dst_dir | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment