Wednesday, September 18, 2019
  • Index
  •  » Automator
  •  » Service How to use current page url in Safari as variable?

#1 2015-09-25 01:48:06 am

fearbabyriffs
Member
From:: Las Vegas
Registered: 2009-11-25
Posts: 29
Website

Service How to use current page url in Safari as variable?

So I am trying to write a service in Automator & cannot figure out how to take the current selected page url of Safari or Chrome to variable within this on run.

I obviously set ytURL explicitly here, but want to use a variable set to the page url instead.

When set explicitly it does work from testing.

on run {input, parameters}
   
    set ytURL to "https://www.youtube.com/watch?v=Y-NB0GiPvh0"
    tell application "Terminal"
        activate
        do script with command ("youtube-dl --extract-audio --audio-format mp3 " & ytURL)
    end tell

    return input
end run

So I guess what automator action step should I have above this one?

Is it "Set variable"? and if so how would I do that?

ANSWER:
Okay this is how I did it:

1st Automator step was "Get current webpage from Safari"
2nd Automator step was "Run Applescript"

on run {input, parameters}
   
    set ytURL to input
    tell application "Terminal"
        activate
        do script with command ("youtube-dl --extract-audio --audio-format mp3 " & ytURL)
    end tell

    return input
end run

Last edited by fearbabyriffs (2015-09-27 04:59:03 am)

Offline

 

#2 2019-08-22 08:50:36 am

bogdanw
Member
Registered: 2019-07-13
Posts: 13

Re: Service How to use current page url in Safari as variable?

You don't have to start Terminal, you can use
AppleScript
on run {input, parameters}
    do shell script "/usr/local/bin/youtube-dl --no-check-certificate --extract-audio --audio-format mp3 " & (input as text)
end run
or
Shell Script { Shell: /bin/bash/  Pass Input: as arguments }:
/usr/local/bin/youtube-dl --no-check-certificate --extract-audio --audio-format mp3 $1

You can set a custom download location by using
do shell script "cd ~/Youtube;" & "/usr/local/bin/youtube-dl --no-check-certificate --extract-audio --audio-format mp3 " & (input as text)

It works with a keyboard shortcut or if you right click the url in the address bar, but I can't get it to work on right click on a url. Any suggestions?

Offline

 
  • Index
  •  » Automator
  •  » Service How to use current page url in Safari as variable?

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)