Skip to content

Instantly share code, notes, and snippets.

@AshMartian
Created October 18, 2017 20:31
Show Gist options
  • Save AshMartian/7369c5754f3a882b19cbcad5fc1f3bd9 to your computer and use it in GitHub Desktop.
Save AshMartian/7369c5754f3a882b19cbcad5fc1f3bd9 to your computer and use it in GitHub Desktop.
# Create shell script, place ffmpeg / youtube-dl / CocoaDialog in the /Applications/Utilities folder
loggedInUser=$(/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }')
cd /Users/$loggedInUser/Desktop/
DESKTOP="/Users/$loggedInUser/Desktop"
RS=`/Applications/Utilities/CocoaDialog.app/Contents/MacOS/CocoaDialog inputbox --informative-text "Youtube URL" --text "Paste Youtube URL here" --button1 "MP3" --button2 "MP4" --button3 "Close" -title "Youtube Downloader"`
URL=$(echo $RS | cut -c 3-)
ANS=$(echo $RS | cut -c 1-1)
if [ "$ANS" -eq "3" ]; then
exit 0
fi
/Applications/Utilities/youtube-dl "$URL" --format mp4
FILE=$(/Applications/Utilities/youtube-dl --get-filename "$URL" --format mp4)
if [ "$ANS" -eq "1" ]; then
OLDFILE="$FILE"
/Applications/Utilities/ffmpeg -i "$DESKTOP/$FILE" "$DESKTOP/${FILE%.mp4}.mp3"
rm -f "$DESKTOP/$OLDFILE"
FILE=${FILE%.mp4}.mp3
fi
/Applications/Utilities/CocoaDialog.app/Contents/MacOS/CocoaDialog msgbox --text "Download Complete" --informative-text "$FILE has been saved to $loggedInUser's desktop." --button1 "Sweet!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment