A bit of help needed guys… I’m trying to develop a shortcut to pass data to the maapl search engine.
I need to take text input for the search (term1 term2 term3 term4, etc) (I can do that), but then open a web browser as:
xttps://maapl.net/search?q=term1+term2+term3+term4
The part I can’t do is to join the input terms together (it needs to count how many there are I guess) with the +'s to add to the engine URL.
Any assistance appreciated.
So entering say ‘BBC News president trump’ into the text input box needs to be changed to ‘BBC+News+president+trump’ so I can finally open the web page as:
xttps://maapl.net/search?q=BBC+News+president+trump’
‘xttps’ used to stop a URL generating in the post.
I can get the test input box up, and open the URL, but I can’t work out to join the input terms together.
Try this…
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
local ans
set ans to display dialog "Enter Search terms…" default answer "" with title "MAAPL Search"
set ans to cleanWhiteSpace(text returned of ans)
on cleanWhiteSpace(aString)
local tid
set tid to text item delimiters -- save current text delimiters
set text item delimiters to "+"
set aString to words of aString as text
set text item delimiters to tid -- restore saved text delimiters
return aString
end cleanWhiteSpace
dbrewood. Shortcuts has a Replace Text action that will do what you want. I included a default answer in the dialog just for testing purposes. The text input after the “Replace” label in the Replace Text action is a literal space typed with the space bar.
Replace Space with Plus Sign.shortcut (21.7 KB)
BTW, the title you gave this thread refers to splitting text. What do you want split (theURL perhaps). If that’s the case, how can the shortcut determine the point at which to split the URL (maybe on the characters “?q”)?
Ah ha thank guys I’ll look at both of these, but it does seem like the replace text option will do the trick. I never knew that was in there! Simplest option 
The splitting text I guess was referring to splitting the input and then recombining it?
And a two-liner using the System Ruby (2.6.10p210) or Ruby 3.4.2 on macOS Sequoia v15.3.2.
use scripting additions
set ans to text returned of (display dialog "Enter search terms separated by space…" default answer "" with title "MAAPL Search")
set ans_plus to (do shell script "/usr/bin/env ruby -e \"puts ARGF.read.split().join('+');\" <<<" & ans's quoted form)
Enter Term1 Term2 Term3 Term4 in the dialog.
Result in ans_plus:
Term1+Term2+Term3+Term4
Thanks, useful to know. The replace text option in the shortcut system itself did work perfectly though 