Tuesday, September 27, 2022

#1 2022-06-01 08:06:13 pm

ale82to
Member
Registered: 2012-09-27
Posts: 41

help "converting"/integrate terminal command to Apple script language

hello eveyone i d like to convert this terminal command to download video to apple script command so i can pass  to  it video title(w) and download url (currentURL)

Terminal Command example:

cd /Users/Al3/Desktop
/usr/local/bin/yt-dlp --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" --referer "*" --external-downloader /usr/local/bin/aria2c --external-downloader-args "--check-certificate=false -j16 -x16 -s16 -k1M" --ffmpeg-location "/usr/local/bin/ffmpeg" "[url]https://s-delivery36.mxdcontent.net/v/911e337eda9bf6c65ac539ab606ee857.mp4?s=wp2pN18OkY9cqP8QLFhrMg&e=1654156052&_t=1654139443[/url]" --output "5.mp4"

Apple Script :


Applescript:

if currentURL contains "hls" or currentURL contains "m3u8" then
       display dialog "Password" default answer ""
       set w to text returned of the result
       
       tell application "Finder" to set homeFolder to path to home folder
       do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js --type info --title \"Video Download\" --subtitle \"New video download started\" --message " & quoted form of currentURL
       
       tell application "Finder" to set homeFolder to path to home folder
       
       ** need help** --> do shell script ..........
cd /Users/Al3/Desktop
/usr/local/bin/yt-dlp --user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36" --referer "*" --external-downloader /usr/local/bin/aria2c --external-downloader-args "--check-certificate=false -j16 -x16 -s16 -k1M" --ffmpeg-location "/usr/local/bin/ffmpeg" "currentURL" --output " & POSIX path of homeFolder & "Desktop/" & w & ".mp4\"

       do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js --type pass --title \"Video Download\" --subtitle \"Video download successful\" --message " & quoted form of w

end if

thanks for the help!


Filed under: #download #shell

Offline

 

#2 2022-06-02 06:07:20 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5563

Re: help "converting"/integrate terminal command to Apple script language

Hi.

I think this turns it into a workable shell script command, but I haven't been able to test it, of course.

Applescript:

do shell script "cd /Users/Al3/Desktop ; /usr/local/bin/yt-dlp --user-agent \"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36\" --referer \"*\" --external-downloader /usr/local/bin/aria2c --external-downloader-args \"--check-certificate=false -j16 -x16 -s16 -k1M\" --ffmpeg-location \"/usr/local/bin/ffmpeg\" " & quoted form of currentURL & " --output " & quoted form of ((POSIX path of homeFolder) & "Desktop/" & w & ".mp4")

path to is a Standard Additions command. It doesn't belong to the Finder. So you could leave out those two 'tell application "Finder" to ' portions of text in your script. In fact there's no point in having the command twice anyway. Another thing is that path to can get the path to the desktop directly, which would save some concatenation if the desktop's always going to be the destination:

Applescript:

if currentURL contains "hls" or currentURL contains "m3u8" then
   display dialog "Password" default answer ""
   set w to text returned of the result
   
   do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js --type info --title \"Video Download\" --subtitle \"New video download started\" --message " & quoted form of currentURL
   
   do shell script "cd /Users/Al3/Desktop ; /usr/local/bin/yt-dlp --user-agent \"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36\" --referer \"*\" --external-downloader /usr/local/bin/aria2c --external-downloader-args \"--check-certificate=false -j16 -x16 -s16 -k1M\" --ffmpeg-location \"/usr/local/bin/ffmpeg\" " & quoted form of currentURL & " --output " & quoted form of (POSIX path of (path to desktop) & w & ".mp4")
   
   do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js --type pass --title \"Video Download\" --subtitle \"Video download successful\" --message " & quoted form of w
   
end if


NG

Offline

 

#3 2022-06-02 08:48:22 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2524

Re: help "converting"/integrate terminal command to Apple script language

To debug errors in long do shell script commands, it makes sense to write them down first in a more readable form. Test and debug following example yourself, because I can't test it for you:

Applescript:


if currentURL contains "hls" or currentURL contains "m3u8" then
   display dialog "Password" default answer ""
   set w to text returned of the result
   
   tell application "Finder" to set homeFolder to path to home folder
   do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js
--type info
--title \"Video Download\"
--subtitle \"New video download started\"
--message "
& quoted form of currentURL
   
   tell application "Finder" to set homeFolder to path to home folder
   
   -- ** need help** --
   do shell script "cd /Users/Al3/Desktop;
/usr/local/bin/yt-dlp
--user-agent \"Mozilla/5.0 (Macintosh; Intel Mac OS X 12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36\"
--referer "
* "
--external-downloader /usr/local/bin/aria2c --external-downloader-args \"
--check-certificate=false -j16 -x16 -s16 -k1M\"
--ffmpeg-location \"/usr/local/bin/ffmpeg\""
& quoted form of currentURL & "
--output \" & POSIX path of homeFolder & \"Desktop/\" & w & \".mp4\""

   
   do shell script "/usr/local/bin/node /usr/local/lib/node_modules/osx-notifier/bin/osx-notifier.js
--type pass
--title \"Video Download\"
--subtitle \"Video download successful\"
--message "
& quoted form of w
   
end if

Last edited by KniazidisR (2022-06-02 09:01:21 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#4 2022-06-02 09:43:42 am

ale82to
Member
Registered: 2012-09-27
Posts: 41

Re: help "converting"/integrate terminal command to Apple script language

thank you very much works perfectly!

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)