Open web page

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Open web page

Post by WilliamL »

In my program I want to be able to use code to run Safari and go to a specific page (e.g. https://world-weather.info/forecast/usa ... arch-2023/) I don't need to read the contents or anything I just want to look at it.

I'm sure I saw this somewhere...
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
Quin
Addict
Addict
Posts: 1133
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: Open web page

Post by Quin »

Code: Select all

RunProgram("open", "https://world-weather.info/forecast/usa/everett/march-2023/", "")
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Re: Open web page

Post by WilliamL »

Thanks Quin,

Works perfectly! I was playing with RunProgram but couldn't get the right combination.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
User avatar
Piero
Addict
Addict
Posts: 923
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Open web page

Post by Piero »

WilliamL wrote: Thu Apr 11, 2024 3:31 am I was playing with RunProgram but couldn't get the right combination.

Code: Select all

#helppath$="/Applications/PureBasic.app/Contents/Resources/help/purebasic/"

Procedure.s sh(search$)
   Protected Output$, shell
   shell = RunProgram("/bin/sh","","",
      #PB_Program_Open|#PB_Program_Write|#PB_Program_Read)
   If shell
      WriteProgramStringN(shell,search$)
      WriteProgramData(shell,#PB_Program_Eof,0)
      While ProgramRunning(shell)
         If AvailableProgramOutput(shell)
            Output$ + ReadProgramString(shell)
         EndIf
      Wend
      CloseProgram(shell)
   EndIf
   ProcedureReturn Output$
EndProcedure

Procedure pbh(s.s)
   s=#helppath$+sh("grep -i '"+s+"' "+#helppath$+~"index.xml  | awk -F'\"' '{ print $(NF-1) }' | head -n 1")
   if s <> #helppath$

      sh( "open -a safari " + URLEncoder(s) )

   EndIf
EndProcedure

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

pbh("runprogram") ; PB Help in Safari
Post Reply