I’m not able to infer what you are doing, so I can’t help write a macro to help. If you explain your exact process, such as which browsers you are using, what you mean by “make changes”, how you currently save your pages to a file, etc., then I should be able to help. I can automate nearly anything, but I need to know what to automate.
That token only tells you the name of the browser. I’m not sure what use that would be. I recommend that you explain the problem in detail before you start talking about solutions. But if you already have a macro that partly works, you can show us that, because that will help us understand the problem.
What do you mean by “it”? You don’t open files by passing a browser name to an action.
If you explain exactly what you re doing, staring with the names of the apps that you open, and explaining how you open the pages that you want to edit, and how you currently save those HTML files, we might be able to help automate this.
P.S. I don’t have Chrome, so I had to make it look like I was using the action that activates Chrome, which is actually just an action to activate Safari, renamed to look like it’s activating Chrome. The activate actions are optional, depending upon whether you want the browser to be made frontmost or not.
There's no need for AppleScript here, and using it is measures of magnitude slower than using built-in Keyboard Maestro actions. @DocOck's solution is a much more efficient way to do it. Why did you want to avoid using Switch?
One advantage of using this macro is that if the local file is already open in a browser tab, the existing tab will be activated. In contrast, most methods would open a new tab.
The advantage over the “Switch” solution is that the browser can be addressed dynamically. Unlike with “Switch,” it doesn't have to be defined in advance.
Okay, but you never mentioned that implementation detail as a requirement, and even now, you haven’t indicated why that is a requirement. But if you had mentioned it, I might have been able to solve your problem using this requirement along with KM actions.
Here’s how to do it in a couple of actions using your new requirement. I tested it. It works for me. But it may not work with ALL browsers (probably not Firefox, for starters.)
One advantage over using KM is that the AppleScript will open the file in the required browser in the background, without disturbing anything. But you can almost replicate that in KM:
If you do want the file opened frontmost and active, just miss out the last Action.
Despite what I said earlier, AS is actually a little faster because you don't have to wait for the browser to come to the front. But different browsers behave differently. If you are opening a file that is already in that browser's active tab -- previewing edits, for example -- Safari will reload in that tab but Chrome will open another one. So choose your method depending on what you want to happen.
I agree. I’m also wondering why yesterday when I ran my 2-line test above, KM did NOT bring the browser window to the front. It displayed cnn.com in the Safari window in the background. But today I can’t replicate that behaviour. Any idea why that happened to me?
That's weird, because it should front the app. In fact, you want it to -- otherwise there's too much chance that the chosen browser opens behind another browser and the "Set Front Browser URL" targets the wrong app.
Although it's worth noting that you don't need the second action -- you can include the URL in the shell command:
I tried the g switch a few years back, and it wasn’t reliable because some apps stole the focus even if g was specified. In this case, the macro is intended to work with “browsers” and I think Chromium browsers do not respect that switch (probably a bug in Chromium.) So your focus revert action above is required for most browsers.
Of course, I should have learned my lesson earlier today to never argue with you, and here I am doing it again. Shame on me.