1

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?

2
  • could you try using full path to python in the script ? Find it by running which python or type python – anki Sep 7 '20 at 17:24
  • Welcome Alfie Stoppani, I've removed your edit as that's not how things work here. Please add your own answer showing the solution that fixed your problem. Thanks. – user3439894 Sep 7 '20 at 19:59
1

Thanks to the answers I got about paths, I was able to solve this. It lead me to this: My Automator Workflow fails because it fails to find the git command within the 'Run Shell Script' command? Need help which solved everything.

Added the following to the start of the script:

export PATH=/usr/local/bin:$PATH
1

This is the standard issue with GUI apps in macOS. These are launched via lanuchd from desktop, no part of the process has run through a shell so what is in any of your shell start up scripts e.g. $PATH does not matter.

What you need to do is use the full path to anything you call in your case the full path to youtube-dl and if that is a script that might need editing to provide full paths to what it calls.

0

Not the answer you're looking for? Browse other questions tagged .