Monday, July 26, 2021

#1 2021-07-20 10:22:47 pm

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

apple script and aria2c (ask for name before downloading)

hello everyone so after many hours (i m justa a begennir with apple script)
i put toghether a script to download video with youtube dl or aria2c.
i need help regarding aria,i want the apple script to ask for a name and then pass it to "do shell script aria etc etc "
here s  my code but the varianble "w" is not corrctly interpreted by aria it stays w!!

code:
set currentURL to the clipboard

if currentURL contains "youtube" then
    tell application "Finder" to set homeFolder to path to home folder
    do shell script "/usr/local/bin/youtube-dl -x --audio-format mp3 -o \"" & POSIX path of homeFolder & "Desktop/%(title)s.m4a\" --ffmpeg-location /usr/local/bin/ffmpeg  " & currentURL
    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 currentURL
else
    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 \"w\" --subtitle \"New video download started\" --message " & quoted form of w
    do shell script "/usr/local/bin/aria2c -j 16 -x 16 -s 8 -k 1M -o \"" & POSIX path of homeFolder & "Desktop/w.mp4\" " & currentURL
    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 currentURL
   
end if


Filed under: #applescript #shell

Offline

 

#2 2021-07-21 01:00:05 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 75

Re: apple script and aria2c (ask for name before downloading)

When troubleshooting applescript/shell combinations, it can be helpful to show the text that will make up the shell command, i.e. remove the 'do shell script' part of the line. Then, if necessary, you can try running that directly in the terminal and seeing how it is treated there.

I'm assuming that you refer to the 'w' in this line:

Applescript:

do shell script "/usr/local/bin/aria2c -j 16 -x 16 -s 8 -k 1M -o \"" & POSIX path of homeFolder & "Desktop/w.mp4\" " & currentURL

It produces this line for the shell:

Applescript:

"/usr/local/bin/aria2c -j 16 -x 16 -s 8 -k 1M -o \"/Users/username/Desktop/w.mp4\" https://www.youtube.com/watch?v=***********"

The 'w' is inside the quotes and so is treated as the literal letter rather than a variable. You'd need to do something like:

"Desktop/" & quoted form of w & ".mp4\"

p.s. You should edit your post, select your code and then click the 'Applescript' button. This will format it properly for this forum.

Offline

 

#3 2021-07-23 12:49:43 pm

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

Re: apple script and aria2c (ask for name before downloading)

Mockman wrote:

When troubleshooting applescript/shell combinations, it can be helpful to show the text that will make up the shell command, i.e. remove the 'do shell script' part of the line. Then, if necessary, you can try running that directly in the terminal and seeing how it is treated there.

I'm assuming that you refer to the 'w' in this line:

Applescript:

do shell script "/usr/local/bin/aria2c -j 16 -x 16 -s 8 -k 1M -o \"" & POSIX path of homeFolder & "Desktop/w.mp4\" " & currentURL

It produces this line for the shell:

Applescript:

"/usr/local/bin/aria2c -j 16 -x 16 -s 8 -k 1M -o \"/Users/username/Desktop/w.mp4\" https://www.youtube.com/watch?v=***********"

thank you very much worked perfectly and thanks for explaining! have a nice day
The 'w' is inside the quotes and so is treated as the literal letter rather than a variable. You'd need to do something like:

"Desktop/" & quoted form of w & ".mp4\"

p.s. You should edit your post, select your code and then click the 'Applescript' button. This will format it properly for this forum.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)