Running terminal script mac osx to open web browser

shell

#1

Hi guys,
I am trying to have a shell command within a julia script. For instance, I am trying to open safari to a specific page.

Any help would be greatly appreciated.

Thanks!
Nakul


#2
run(`open -a Safari http://www.google.com/`)

… supposedly you’re running macOS


#3

Thanks, that works great!


#4

I am attempting to have a variable name for the link so that I can alter or push a start-time flag to the end of a youtube link.

This is what I have but it’s not working.

link = https://www.youtube.com/watch?v=venyMc86h8U

a = run(`open -a Safari `+ link)

#5
link = "https://www.youtube.com/watch?v=venyMc86h8U"

a = run(`open -a Safari $link`)

#6

@favba’s solution is probably the best one, but a couple of other things to note. First - your link = http... code throws an error because it’s not parsed. Note the quotes around the link in favba’s solution - that makes it a string.

Another thing, you might be familiar with python syntax for string concatenation, where eg "a" + "b" == "ab", but in julia this is done with *

julia> "a" + "b"
ERROR: MethodError: no method matching +(::String, ::String)
Closest candidates are:
  +(::Any, ::Any, ::Any, ::Any...) at operators.jl:502
Stacktrace:
 [1] top-level scope at none:0

julia> "a" * "b"
"ab"

Though this type of syntax doesn’t work with Cmd and String, so you should use interpolation as suggested.