Skip to content

Instantly share code, notes, and snippets.

@aflores
Created August 20, 2017 16:05
Show Gist options
  • Save aflores/eeb2084f69b71e54d1f39c23d61a16e2 to your computer and use it in GitHub Desktop.
Save aflores/eeb2084f69b71e54d1f39c23d61a16e2 to your computer and use it in GitHub Desktop.
AppleScript file to download youtube videos
(*
script to download videos from youtube using the youtube-dl program
you can paste this code in a ScriptEditor file or use it inside a
'Run AppleScript' block in an Automator Application
*)
set question to display dialog "Youtube URL to fetch?" default answer "" buttons {"Cancel", "Open in Browser", "Download"} default button 3
set pageURL to (text returned of result)
if pageURL is "" then return "No URL"
set choice to (button returned of question)
set progress total steps to 1
set progress completed steps to 0
set progress description to "Downloading video..."
if choice is "Download" then
try
set pid to do shell script "cd ~/Downloads/youtube/; /usr/local/bin/youtube-dl --newline " & pageURL & " > /tmp/vidstatus 2>&1 & echo $!"
delay 1
repeat while ((do shell script "kill -0 " & pid) is "") -- check if pid is still responding
-- display dialog "Status: " & (do shell script "tail -n1 /tmp/vidstatus") -- display last line of output
set progress completed steps to 0
end repeat
on error
set progress completed steps to 1
display dialog "Download complete!" -- eh, success, hopefully :)
set progress total steps to 0
set progress completed steps to 0
set progress description to "Done!"
end try
else if choice is "Open in Browser" then
try
open location pageURL
on error
display dialog "Cannot open " + pageURL + " !"
end try
end if
return input
@whitecatcafe
Copy link

Hi, this script isn't working in Catalina 10.15.7, I get the "return input" undefined and also no video is downloaded at all. I tried your revision too but encountered the same problem...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment