So for my work, I am constantly generating links that have to variables that need changed (Ex. http://www.thedomain.com/ajdkeial.html?keyword1={keyword1}&keyword2={keyword2} )
The link is generated with those brackets, to be replaced. Now I am completely illiterate with code, but I am looking for a way to: Select the text, and replace {keyword1} with the actual keyword I want, and {keyword2} with the second.
I envision this being done with clipboard history for the variables to grab via the app "Alfred", however I'm not sure how I could write a script that grabs these variables and replaces the text, then gives me the finished product. If anyone had any direction to go to, it would be greatly appreciated.
Best Answer
This is a job for text item delimiters. If you aren't familiar, a delimiter is a separator, normally between words the separator is a space. With text item delimiters, you can change the normal space to any text value you want. In this case, you would make "{keyword1}" the text item delimiters, then the script will see the original text as only two words, everything before "Keyword1" and everything after is the second word. Then you set text item delimiters to whatever you want to replace the "{keyword1}" with, and cram the two words back into one text item.
I've written some basic code that does what you ask below, with some inline comments. One note, whenever playing with text item delimiters, always finish the script by setting them back to the default. I stored the original text item delimiters in a variable called "tid", then set them back at the end of the script.