I've got a number of macros that do things in Chrome with the system clipboard: open a URL that I've copied, search Google for the text I've copied, and so on. But I'm considering switching to Brave as my main browser, and I'm having trouble adapting these macros to it. Obviously all the "Set Google Chrome URL" actions have to be replaced with "Open URL" actions -- but I keep getting "invalid URL" errors. Why should the "Open URL" action balk at having
in its text field, when this worked just fine in a "Set Google Chrome URL" action? And how can I make this, and similar attempts, work? I have the feeling that if I can figure out the problem in this basic macro, I should be able to adapt the others...there's got to be something obvious that I'm missing?
Chrome and Safari are the only browsers that are directly supported by KM and scripting. You will be facing an uphill battle trying to automate any other browser.
The Open a URL action will open any valid, properly encoded, URL in the default browser. You probably need to encode the Clipboard when you use it in a URL.
Actually, Brave Browser is based on the Chromium web browser that Google Chrome is made from, and is therefore AppleScriptable. I haven't tested it, but it should have the same scripting features as Google Chrome.
Brave Browser AppleScript Dictionary
Brave Browser.app terminology
/Applications/Brave Browser.app
Standard Suite
Common classes and commands for all applications.
Commands
save -- Save an
object.
reference -- the object to save, usually a document or window
[infile] -- The file in which to save the object.
[astext] -- The file type in which to save the data.
Can be 'only html' or 'complete html', default is 'complete
html'.
open -- Open a
document.
list of file -- The file(s) to be opened.
close -- Close
a window.
reference -- the document(s) or window(s) to close.
quit -- Quit the
application.
count -- Return
the number of elements of a particular class within an object.
reference -- the object whose elements are to be counted
[eachtype class] -- The class of objects to be counted.
Result: integer -- the number of elements
delete --
Delete an object.
reference -- the object to delete
duplicate
-- Copy object(s) and put the copies at a new location.
reference -- the object(s) to duplicate
[tolocation reference] -- The location for the new
object(s).
[with propertiesrecord] -- Properties to be set in the
new duplicated object(s).
Result: reference -- the duplicated object(s)
exists --
Verify if an object exists.
anything -- the object in question
Result: boolean -- true if it exists, false if not
make -- Make a
new object.
newtype class -- The class of the new object.
[atlocation reference] -- The location at which to
insert the object.
[with dataanything] -- The initial contents of the
object.
[with propertiesrecord] -- The initial values for
properties of the object.
Result: reference -- to the new object
move -- Move
object(s) to a new location.
reference -- the object(s) to move
tolocation reference -- The new location for the
object(s).
Result: reference -- the moved object(s)
print -- Print
an object.
reference -- The file(s) or document(s) to be printed.
set -- Set an
object's data.
reference
toanything -- The new value.
get -- Get the
data for an object.
reference
Result: anything
Classes
application
-- The application's top-level scripting object.
Plural name:
applications
Properties:
name (r/o) text -- The name of the application.
frontmost (r/o) boolean -- Is this the frontmost
(active) application?
version (r/o) text -- The version of the application.
bookmarks bar (r/o) bookmark
folder -- The
bookmarks bar bookmark folder.
other bookmarks (r/o) bookmark
folder -- The
other bookmarks bookmark folder.
Elements:
window -- by name,
index, relative, range, test, id
bookmark
folder -- by name, index, relative, range, test, id
window -- A
window.
Plural name:
windows
Properties:
name (r/o) text -- The full title of the window.
id (r/o) integer -- The unique identifier of the
window.
indexinteger -- The index of the window, ordered
front to back.
boundsbounding rectangle -- The bounding rectangle of
the window.
closeable (r/o) boolean -- Whether the window has a
close box.
minimizable (r/o) boolean -- Whether the window can be
minimized.
minimizedboolean -- Whether the window is currently
minimized.
resizable (r/o) boolean -- Whether the window can be
resized.
visibleboolean -- Whether the window is currently
visible.
zoomable (r/o) boolean -- Whether the window can be
zoomed.
zoomedboolean -- Whether the window is currently
zoomed.
active tab (r/o) tab --
Returns the currently selected tab
modetext -- Represents the mode of the window which
can be 'normal' or 'incognito', can be set only once during
creation of the window.
active tab indexinteger -- The index of the active
tab.
You probably need to encode the Clipboard when you use it in a URL.
Can you suggest how? Right now I'm filtering it with "Remove Styles," "Trim Whitespace," and "Percent Encode for URL," and yet if I copy a single word from a Word document, run those filters, and pass
to the Open a URL action, it fails with "invalid URL" but doesn't give me any way of figuring out what the problem is. If I instead have KM paste the same text string into the address bar and type Return, it works; the search is performed. It makes no sense to me that this action would succeed when the other fails... (ETA: and when it worked fine, even without any filtering or encoding, with a "Set Google Chrome URL" action!)
Hah, got it! I found that it worked if I removed the quotation marks around %SystemClipboard% in the URL. But if I have more than one word, I want to be searching for the phrase as a phrase, so I do want the quotation marks in the URL. So I set a variable to "%SystemClipboard%" (the clipboard wrapped in quotation marks), filtered the variable with Percent Encode for URL, and then passed the Open URL action the text
Moral: the Set Google Chrome URL action can handle characters in the URL it's passed that the Open URL action can't. I didn't expect that plain-text quotation marks would be a problem, but now I know!
Thanks for sharing that. I was not aware of the Brave Browser.
It looks very interesting.
@peternlewis, any chance that KM might provide direct support for Brave Browser?
I'm particularly interested in the behaviour of the "FrontBrowser" actions and tokens.
I was not aware of the Brave Browser. It looks very interesting.
There are some unpleasant things about it (its optional ad exchange program and monetization thereof look sleazy at a quick view, but it's optional), but boy howdy is it ever fast. So I'm giving it a try, and in the process reworking my browser macros to work with any browser, not just my previous default of Chrome. And learning things along the way (It would certainly be great if "Front Browser" actually meant front browser, not just "whichever of Chrome and Safari was last used"!)
Probably not, not unless it becomes more popular. Although you should be able to use the existing preferences for Google browser settings to point at it.
The AppleScript name is used in AppleScript's which control the respective browser in the form of tell app “”. Note that the Safari browser must still behave like Safari, and the Chrome browser must behave like Chrome, or the actions will not work. Do not bother trying to set them to Firefox or something like that as it will not work. All this allows you to do is select a specific version of Safari or Chrome respectively.
Peter, thanks for sharing/clarifying.
That at least gives any one who want to ONLY run Brave an option to do so, but at the expense of not having access to Google Chrome.
AFAIK, the scripting model of Brave Browser is identical to Google Chrome. If that is the case, I would hope the effort to change KM to support Brave would be minimal.
Please give this a closer look. There are many who have switched from Safari to Google Chrome because Chrome is faster, better UI, and more extensible (more browser extensions). However, many don't switch to Chrome because of Google's bad reputation on privacy.
I hadn’t heard of Brave before; it looks interesting, and if it’s reasonable for KBM to support it, that’d be great.
But if so, what about all the other Chromium-based browsers that folk use? Vivaldi is quite popular, for example (I use it), Edge, and Chromium itself? I think there are a bunch of others, too. And is Opera Chromium-based now? It’d be lovely if all these were supported, but I worry that it might be a time drain on Peter — on-goingly.
Peter, when I try to read these defaults, I get an error:
$ defaults read com.stairways.keyboardmaestro.engine AppleScriptGoogleChromeBundleID
2019-05-09 12:45:26.600 defaults[1769:64516]
The domain/default pair of (com.stairways.keyboardmaestro.engine, AppleScriptGoogleChromeBundleID) does not exist
In fact, when I just do a read without a key to get all defaults, it works, but there is no key for "AppleScriptGoogleChromeBundleID"
So if I set the defaults for Brave Browser, how do I restore to use Google Chrome?
I will add it as a potential match for the front browser tokens - as long as it behaves the same as Google Chrome, it should work. But I cannot test this.
Note that like read will read everything if you omit the key, delete will delete everything if you omit the key (I believe), so one should use caution when using defaults delete.
Unfortunately, this has no impact on the FrontBrowser Actions and Tokens.
Is there another hidden pref that will allow Brave Browser to be included in the FrontBrowser Actions and Tokens?
Does this include FrontBrowser Actions, like Javascript in FrontBrowser?
FYI, right after you provided us with the very useful FrontBrowser Actions/Tokens, I converted all of my Macros to take advantage of them, so my Macros work equally well with both Safari and Chrome.
Now, I'd very much like for Brave Browser to be included as a FrontBrowser.