Is it possible to use the "Search the Web" action with the last typed search text? I tried the following but it doesn't work. It seems like I need to have two dialogs pop up one to easily get the search string to then put into the search string.
I know I could do something like I do with the YouTube search I have but this is overly complicated.
Thank you, I actually did check there first and posted a question about that elsewhere to not muddy the waters here.
What is odd is that "Search the Web" seems to reference %Search% but yet it doesn't actually use what is in that token. The full script I was working on actually was trying to reference %Variable%Search%
What do you mean "Search the Web". Are you talking about a web page, someone else's macro, or the macro you wrote?
Anything that references "%Search%" is referencing a variable, not a token.
It's not a token. It would be a variable.
I will add that I think it may be possible to solve your needs using a combination of methods. I'm trying to solve it right now. If I succeed, I will post my solution in this thread. Part of the problem here is that people don't always type the URL string in sequential order. E.g., sometimes they use the mouse or the arrow keys to edit the URL. My method may not catch some of those cases, so it may miss some URLs.
However if I have that same text in the clipboard and run the macro with nothing selected it doesn't pop up empty or with what was the last text in the clipboar and just doesn't work.
Wow, I never noticed that before. (To be fair, I don't use that action.) That action seems to have been written sloppily. I.e., it neglected to use the characters "%Variable%" when it references a variable. Unless I'm missing something, that would seem to be a typo. (It's legal, but it's not using the best practice.)
I'm still working on a possible solution for you. I like tricky problems like this, and if my solution isn't very good, you can ignore it.
Doesn't look like it -- it seems to be a token or variable internal to that Action.
But you can roll your own version of the Action with a global variable, a Prompt Action that both uses and sets that global, a URL encode Filter, and an "Open a URL" Action -- plus some token concatenation, of course!
I have a different way to "roll my own." I think I just got it working, and I will upload it shortly. It doesn't require "Prompt with List" or any user interaction. My macro intercepts what the user types. It's not easy to explain, so you can read it for yourself, shortly...
Ok... You may not like my solution, but here it is. It was tricky for me to write, (it took hours to write, due to many unexpected technical issues) and it's the first time in years I had to use the %LineFeed% token in a macro.
This macro should be placed in a macro group which is active ONLY when your browser window is open (the only browser I tested was Safari. It may need modifications to work in other browsers.) And this macro uses an image detection action which means it won't work in Dark Mode, unless you modify it to work in Dark Mode.
In short, what this macro does is watch what you type in the URL field, and place that text into a global variable called LastSearch. It will delete previous lines so that only that "last line" is recorded. It certainly will not work with 100% accuracy, because many people use backspaces and mouse clicks when entering URLs.
There are two disabled actions at the end of the macro. They were used for debugging, and I left them in this macro (disabled) in case anyone wants to try to improve this macro. They could prove useful for people who want to improve this macro.
I wrote this macro because it was hard to do. Just like climbing a mountain. It may look short and simple, but there are many little tricky problems I had to solve to make this work, which I have not documented here.
It detects normal typing. It needed special handling for the Return/Enter key.
I'm not sure what you mean by "a search". It doesn't detect mouse clicks or URL changes through other methods besides typing, although perhaps it could be upgraded to detect some additional kinds of URL changes like these.
A search: Me typing "Keyboard Maestro Forum" into the address bar and hitting Return.
A normally-typed URL: Me typing "https://forum.keyboardmaestro.com" into the address bar and hitting Return.
But I'm guessing @skillet's looking for something that replicates the "Search the Web" action but defaults the prompt input to whatever the last search was -- something like:
Ahh. No, at this point my macro treats anything being typed as an address to be saved. It doesn't even validate the address, so a search would count as an address.
I don't really know what skillet's real intent was. Perhaps your interpretation is correct. I would never want to argue with you, as your interpretation skills are superb.
I just saw a nice, tricky problem here that I thought I could solve and I did. It was fun, even if this wasn't what skillet wanted.
Oh my goodness, thank you and I apologize for taking up so much of your time working on this!
Wow that is pretty wild and nice work on this. I would never even thought of something like this, it's a bit of a keystroke logger.
Yes that is what I was looking for without having to modify it for each way different websites do their search since the "Search the Web" action does various means of prebaked searching strings like underscores, + signs etc. depending on the website you are searching.
Yes, you got it. This is pretty close to the stuff I was doing in the YouTube example above.
The best I could come up with is something like this but it requires you to get two dialog promptings. Just a double enter is all that is needed but still seems silly to have to do that.
Idle classification of the %Seach% thingie based on behavior:
I think of it as a substitution placeholder in a query url, AKA format specifier because, well, it walks and quacks like one. Where you place the %s placeholder is where in the query url your search terms will land.
The unix printf %s thingie behaves the same way:
A command line using the printf command in AppleScript:
do shell script "printf "Hello, %s\n" "World""
In the terminal:
printf "Hello, %s\n" "World"
The value that is substituted doesn't stick around. It is good for one use only.
Web browsers do the same thing with a search term in the address bar.
From days gone by:
Google uses ,%s, as a placeholder for users to manage their search engine queries:
(Once on the above page look for:"'URL with %s in place of query' field")
Keyboard Maestro wiki %Search% doesn't explictly make this conection, but the list of urls with the placeholder,%Search% are look pretty similar to what you'll find if you follow the instructions on google page. More to the point, it acts like a format specifier, er, placeholder, er, thingie.
All it does for you, I think, is URL encode the search term -- you have to do the rest, although that's only copying the appropriate URL from the Action's web page.
For my macro above, all you have to do is add another field to the prompt for search engine selection then "Switch/Case" the engine choice to combine the engine-specific URL with the search term. And you could either default the engine choice or have "last used", as with the search term. You could even choose on the fly with an hot-key modifier...
Abosolutly, and thank you for your help on this. That is what I meant by the following but you may mean something else.
I guess on some servers they return something easier to read for the end user which is nice. I'll take + over %20 too bad that wasn't what became the standard for spaces in the first place.