Hi all! First post here.
A workflow of mine involves having a script launch a bookmarklet in Google Chrome. I can, it is true, put the JS code to be executed directly into my script, but that means changing my code in 2 places every time I change something.
So with Applescript, opening a bookmark in Chrome is trivial:
tell application "Google Chrome"
if not (exists window 1) then reopen
set coef to URL of bookmark item "Coef" of bookmark folder "Bookmarks Bar"
open location coef
end tell
But when trying this in JXA, everything goes to hell.
I've tried countless variations on the following code,
var app = Application('com.google.Chrome')
var frontWindow = app.windows[0]
var myBM = app.bookmarkFolders.whose({title: "Bookmarks Bar"})
var myBM = app.bookmarkFolders["Bookmarks Bar"]
var myBM = app.bookmarkFolders.title("Bookmarks Bar")
//etc ad nauseam
and cannot for the life of me get a handle on a bookmark folder, let alone a bookmark item. bookmarkFolder vs. bookmarkFolders, nothing helped.
The last line actually got me an array with the names of the two top-level folders, but that's the closest I got to anything.
Anybody has an idea how this gets done? Thanks!