I got a mac last week and am trying to learn the basics by coding a few projects I came up with. I’ve been creating a few apps I can place on the dock that automate simple functions that I use often. So far, all my programs have worked by creating a zsh script and getting Automator to ‘Run Shell Script’, however this particular program isn’t fully working, although, if I run my program through terminal, it works perfectly.
I’m trying to create a program that can be executed after a YouTube url has been copied into the clipboard. The program takes the url and runs it through ‘youtube-dl’ and downloads the audio into the Downloads folder. I tried to learn how to do this from Z shell alone, but I was very overwhelmed with it and I decided to use python which I already know.
Here’s what I’m doing:
My Python3 code:
import os url = os.popen("echo `pbpaste`").read() os.system("youtube-dl -f 'bestaudio(ext=m4a)' '"+url+"'")
My zsh file:
#!/bin/zsh cd /Users/admin/Downloads python3 /Users/admin/Documents/Scripts/Automation/ytGetAudio/ytGetAudio.py
I then made it executable with “chmod +x /Users/admin/Documents/Scripts/Automation/ytGetAudio/ytGetAudio.zsh”
When I run my program from the terminal, everything works great, and the file is downloaded into Downloads, but when I use Automator to “Run Shell Script” and I get it to run the same zsh script it doesn’t download anything. I tested it by creating a pop-up message box in the python script; that worked, so the script is running, but something isn’t working because nothing is downloading when I run the ‘.app’ file.
Can anyone please help me with this? 🦄