Tuesday, 1 January 2019

macos - How can I open a non-http URL (Chrome extension) in Google Chrome from the terminal in OS X?


I'm trying to add a shortcut to open Chrome with a non-http url from a bash script. This is what I've got:


/usr/bin/open -a "/Applications/Google Chrome.app" 'chrome-extension://hgmloofddfasdfasdffgcellkdadsfadsfbjeloo/RestClient.html#RequestPlace:saved/2'   

Since the argument doesn't start with "http" Chrome tries to open it as a file, which of course doesn't exist, nor is it what I want.


Is there a way to make Chrome treat that as a url?


Edit:


@mjb - that's almost working. Thank you.


The extension (Advanced Rest Client) is installed locally. However, there's something different about loading it as a file and loading it with "chrome-extension://". When I load it as a file, I don't get the data (my rest requests) that has been saved as part of the app. Without that, it's useless.


Here's what I'm running from bash:


/usr/bin/open -a /Applications/Google\ Chrome.app /Users/me/Library/Application\ Support/Google/Chrome/Default/Extensions/hgmloofdphfgcellkdfbfbjeloo/3.1.7_0/RestClient.html

It loads my app, and it comes up - just without my context/data. When I click the extension in Chrome, it uses the following url:


chrome-extension://hgmloofdphfgcellkdfbfbjeloo/RestClient.html#RequestPlace:saved/2

Note that the hash on the end makes no difference. The UUID is the same as the local directory.


I also tried loading it with:


https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffgcellkdfbfbjeloo/RestClient.html

That just brings up the Chrome Web Store page for this app.


The data I want to use does appear to be in the database file for this extension, which is in:


/Users/me/Library/Application Support/Google/Chrome/Default/databases/chrome-extension_extension_hgmloofddffdnphfgcellkdfbfbjeloo_0/5

Any ideas?



Answer



I believe open attempts to process the passed URL before passing it on to Chrome. Since it doesn't recognize the 'chrome-extension' scheme, it interprets it as a relative file path.


Instead, you can use AppleScript to accomplish this.


osascript <set theURL to "chrome-extension://nmmhkkegccagdldgiimedpiccmgmieda/html/craw_window.html"
tell application "Google Chrome"
if windows = {} then
make new window
set URL of (active tab of window 1) to theURL
else
make new tab at the end of window 1 with properties {URL:theURL}
end if
activate
end tell
EOD

Note that the above code is actually AppleScript wrapped in a bash heredoc and passed to the osascript command, so you can drop it right into the terminal or a shell script.


No comments:

Post a Comment

Where does Skype save my contact&#39;s avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...