Quotation marks needed in a message object to enable a hyperlink searching a website - but how?

    MaxMSPadvanced

    Russell Richards
    Sep 08 2023 | 6:52 pm
    It's great to be able to link out to a web browser from a message box.
    I have been able to concatenate the google sitesearch with single word search terms i.e.
    ; max launchbrowser https://www.google.com/search?sitesearch=cycling74.com&;q=RNBO
    However, when trying to get an exact phrase the message box will turn this:
    into this:
    "https://www.google.com/search?sitesearch=cycling74.com&;q=RNBO+Raspberry Pi" (before the concatenation with ; max launchbrowser)
    How can I get it to be:
    ; max launchbrowser https://www.google.com/search?sitesearch=cycling74.com&;q=RNBO+"Raspberry Pi"
    in the message box ready to launch the correct web page.
    N.B. Typing the link in manually Google automatically inserts a %20 in the gap between "Raspberry" and "Pi"
    Any help with this conundrum would be much appreciated as it is stalling an app at the moment.
    Cheers
    Russell

    • TFL's icon
      TFL
      Sep 08 2023 | 8:04 pm
      I got a working solution:
      ;
      max launchbrowser "https://www.google.com/search?sitesearch=cycling74.com&q=RNBO+\\\"Raspberry Pi\\\""
      So put the whole URL in quotation marks, and triple escape quotation marks from the request with backslash! This said, be careful when you copy this kind of text from a Max message box then past it here, as it adds an extra semicolon between & and q for some reason (see your original post), and we don't want it when we copy that resulting text and past it back into a Max message. EDIT: apparently you can avoid quotation marks around the whole URL, but then you need to replace spaces by %20 or +. The %20 is the "litteral" translation of a space character, although the + does the same in an expression between quotation marks.
      ;
      max launchbrowser https://www.google.com/search?sitesearch=cycling74.com&q=RNBO+\\\"Raspberry%20Pi\\\"
      works too.
      Share
    • Roman Thilenius's icon
      Roman Thilenius's icon
      Roman Thilenius
      Sep 08 2023 | 9:22 pm
      adding %20 seems to be the simplest way; what works from the browser textfield will also work from open transport (or however that is called today), but using + for google is probably even better.
    • TFL's icon
      TFL's icon
      TFL
      Sep 08 2023 | 9:37 pm
      I think OP wants to make the following request: `RNBO "Raspberry Pi" site:cycling74.com` and not `RNBO Raspberry PI site:cycling74.com` so that Googles searches for the exact expression "Raspberry Pi" and not any combination of "Raspberry" and/or "Pi". Apparently the + operator is depreciated since 2011 and gives inconsistent results.
    • Roman Thilenius's icon
      Roman Thilenius's icon
      Roman Thilenius
      Sep 08 2023 | 10:15 pm
      i totally missed that you still need the quotation marks no matter how you supply the space.
      that + for the "normal" space is confusing, i would prefer to write
      ; max launchbrowser https://www.google.com/search?sitesearch=cycling74.com&;q=RNBO%20\\\"Raspberry%20Pi\\\"
      which works equally.
      more difficult is... how to format such a messagebox containing spaces programmatically in max. :)
      p.s.: in many cases using a hyphen between two words gives you almost the same results in search engines like google, simpy because the term does not exist written exactly like that. this way it is really easy to format the strings required without any special character and data type magic.
    • TFL's icon
      TFL's icon
      TFL
      Sep 08 2023 | 11:19 pm
      more difficult is... how to format such a messagebox containing spaces programmatically in max. :)
      It's a (ugly but functional) start :)
      Max Patcher
      In Max, select New From Clipboard.
      Show Text
      EDIT: use [regexp " " @substitute %%20] to get %20 instead of +
    • Roman Thilenius's icon
      Roman Thilenius's icon
      Roman Thilenius
      Sep 08 2023 | 11:27 pm
      hehe, except that %20 can not be written into sprintf. :)
      (make sure to limit textedit to 1 line and add a mechanism for autoclear and return= shoot)
    • TFL's icon
      TFL's icon
      TFL
      Sep 08 2023 | 11:58 pm
      Why would you use [sprintf] when [regexp] writes the %20 and [combine] combines everything together?
      Max Patcher
      In Max, select New From Clipboard.
      I'm intrigued even though i think we've gone too far for OP's question :)
    • Roman Thilenius's icon
      Roman Thilenius's icon
      Roman Thilenius
      Sep 09 2023 | 12:04 am
      combine is too newish for me, and regexp too complicated.
      and of course i structured it modular so that you can add more terms or terms of three words without thinking too much.
      can someone explain why with [list] the triple backslash gets lost and with [combine] not?
    • Russell Richards's icon
      Russell Richards's icon
      Russell Richards
      Sep 09 2023 | 9:32 am
      Hey Both
      Fantastic work. I had no idea how to do this and you've supplied the solution(s).
      I am going with TFL [combine] method, partly because I've never used [combine] before.
      Re. %20, using :
      RNBO+\\\"Raspberry+Pi\\\"
      results in:
      RNBO \"Raspberry Pi\" site:cycling74.com
      on the browser for some reason so no %20 problem Thanks so much for your help.
      Russell
      P.S.
      Nothing is ugly in Presentation mode