0

Long time listener (and a massive fan, this platform has me gotten out of predicaments more times that I can count), first time writer:

I am looking after a project where we run several Raspbian installs (Jesse Lite) that run chromium via an server in fullscreen - the whole boot process is automated - and the two tabs that get opened come from the /.config/chromium/default/preferences file;

In the relevant section, it says:

{"restore_on_startup":4,"startup_urls":["http://www.example.com/","https://www.example.org"]}

Since these units are essentially headless and I want to (Apple)Script my way to changing these URLs remotely, I looked into calling sed via ssh with public key on the raspberry pi 400s, and I have made good progress around the ssh and public key situation, but I am still not finding it easy to get my head around patterns and (double) escaping this query...

Purely on MacOS first, before getting into the ssh side of things, this is what I have come up with thus far:

sed -i .new 's/"startup_urls":[".*"]}/"startup_urls":["http://www.example.net","http://www.example.com"]}/g' ~/Library/Application\ Support/Google/Chrome/Default/Secure\ Preferences

However, that just gives me:

sed: 1: "s/"startup_urls":[".*"] ...": bad flag in substitute command: '/'

Any help and/or pointers greatly appreciated, otherwise - carry on!

Cheers,

Fred

FL K
  • 1
  • I *think* the preferences file is JSON and you might be better off using `jq` to process it than `sed`. https://stackoverflow.com/a/42718624/2836621 – Mark Setchell Jun 24 '22 at 13:42
  • If you want to try `jq` on your Mac, you can install with **homebrew** using `brew install jq`. – Mark Setchell Jun 24 '22 at 13:44

1 Answers1

0

It would seem there are a few issues here.

  • The default delimiter / is conflicting with characters in your input data, you would need to use an alternative delimiter
  • The start of the bracket is never matched [ as it needs to be escaped

You can try this sed to match and replace everything within the brackets

$ sed -i.bak s'|\[[^]]*|["http://www.example.net","http://www.example.com"|' ~/Library/Application\ Support/Google/Chrome/Default/Secure\ Preferences
{"restore_on_startup":4,"startup_urls":["http://www.example.net","http://www.example.com"]}
HatLess
  • 10,622
  • 5
  • 14
  • 32