Chrome Extensions - POSTman

easyedc
Valued Contributor II

I'm working on tracking our Google Chrome extensions and the first one that's been turned in to track is POSTman. Normally for our tracking I write a quick extension attribute to read a plist or run a command to get a version but with these Chrome extensions (reading a .json file) I'm scratching my head.

If I run a simple

cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p

from Terminal, I get an output I can work with :```
"version":"0.8.0.4",

If I try to expand that to an extension attribute script it breaks using:

!/bin/sh

PST=cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p
echo "<result>$PST</result>"
```

Any help/thoughts would be appreciated.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor III

OK, I didn't take a close look at what you posted above before, but I think I see the issue now. If what you posted is what you actually have in your Extension Attribute script:

#!/bin/sh
`PST=cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p`
echo "<result>$PST</result>"

Then you have your tic mark in the wrong spot. It needs to come between the = and the 'cat', as in:

PST=`cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p`

The way you had it it was thinking you wanted to run a command starting with PST=cat, which isn't valid.

View solution in original post

4 REPLIES 4

mm2270
Legendary Contributor III

Breaks in what way exactly?

You can try placing the variable in curly brackets.

echo "<result>${PST}</result>"

its possible the quotes that are already in the variable is throwing it off. Do you need the "version: part of it in there? If not, I would just strip it out of your results and get just the number.

`PST=cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p | awk -F: '[Print $2}' | sed 's/,$//'`

easyedc
Valued Contributor II

Sorry @mm2270, should have used better choice of words. if I run the script as I built it, and even with your suggested mods, it doesn't parse out the line that i'm needing but instead spits out:

admin$ /var/folders/gf/mpv9vrrd3f98wts038s2j9hm0000gn/T/Cleanup At Startup/untitled text 4-389560365.224.command ; exit;
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 2: name:__MSG_name__,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 3: version:0.8.0.4,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 4: icons:{: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 5: 16:icon_16.png,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 6: 32:icon_32.png,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 7: 48:icon_48.png,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 8: 128:icon_128.png: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 9: },: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 11: app:{: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 12: launch:{: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 13: local_path:index.html: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 15: },: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 17: default_locale:en,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 18: permissions:[cookies,: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 19: content_scripts:[: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 21: matches:[http://getpostman.com/*,: No such file or directory
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 22: js:[js/listener.js],: No such file or directory
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 23: run_at:document_end: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 25: ],: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 27: manifest_version:: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 28: content_security_policy:: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 29: offline_enabled:true: command not found
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 30: syntax error near unexpected token `}'
/Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json: line 30: `}'
<result></result>

I've tried to get it simply spit out "line 3" but fail at that, too.

mm2270
Legendary Contributor III

OK, I didn't take a close look at what you posted above before, but I think I see the issue now. If what you posted is what you actually have in your Extension Attribute script:

#!/bin/sh
`PST=cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p`
echo "<result>$PST</result>"

Then you have your tic mark in the wrong spot. It needs to come between the = and the 'cat', as in:

PST=`cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p`

The way you had it it was thinking you wanted to run a command starting with PST=cat, which isn't valid.

easyedc
Valued Contributor II

Sometimes you can't see the forest through the trees... Thanks

Ended up just doing a simple cut with ```

!/bin/sh

PST=cat /Library/Application Support/Google/Chrome/External Extensions/chrome/manifest.json | sed -n 3p | cut -c16-22
echo "<result>$PST</result>"
```