Running Jamf scripts that contain Visual Studio Code cli commands?

chrismorga
New Contributor II

Hey all,

Apologies in advance if this questions comes across as thick-headed - I'm very new to Jamf and bash scripting in general.

We have Visual Studio Code installed on our lab machines, and would like to use Jamf Remote to install some plugins for VScode.

To do this, Jamf needs to be able to run

code --install-extension foo.vscode.extension

We've managed to add code cli commands to the path variable from Jamf remote by writing the following script:

#!/bin/sh
sudo touch /etc/paths.d/vscode
sudo bash -c "echo /Applications/Visual Studio Code.app/Contents/Resources/app/bin > /etc/paths.d/vscode"

This can be pushed to our machines and will work once the Macs are restarted, allow us to locally install vscode extensions via command line.

The problem comes trying to push the vscode commands via Jamf remote - I don't think that Jamf (as root) can see the path variable to run the vscode commands. I think this will hold true even If I sudo -i into the same user that has the path variable set, since that doesn't carry over?

If anyone can push me in the right direction for getting the Jamf user to be able to install these extensions, that would be great.

Thanks!

1 ACCEPTED SOLUTION

chrismorga
New Contributor II

I sorted this out. For future readers:

Use which code (in this case, will work for any cli command) to get the full path to the cli command.

Next, use the full path as a command to run what you need. in my case it's /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code -c to run code cli commands. note that -c turns your path into an executable (someone should fix my terminology on this, but it makes sense I think) and allows you to run the commands as if you properly switched users into the user that has your cli path environment correctly configured.

NOTE! This doesn't actually install visual studio extensions onto your lab machines. I'm marking this solved because this method resolves successful code. What it did do was install a bunch of vscode extensions into my jamfadmin home directory. Morning coffee reminded me that I can just package up those extension folders and deploy them via policy, which worked.

View solution in original post

1 REPLY 1

chrismorga
New Contributor II

I sorted this out. For future readers:

Use which code (in this case, will work for any cli command) to get the full path to the cli command.

Next, use the full path as a command to run what you need. in my case it's /Applications/Visual Studio Code.app/Contents/Resources/app/bin/code -c to run code cli commands. note that -c turns your path into an executable (someone should fix my terminology on this, but it makes sense I think) and allows you to run the commands as if you properly switched users into the user that has your cli path environment correctly configured.

NOTE! This doesn't actually install visual studio extensions onto your lab machines. I'm marking this solved because this method resolves successful code. What it did do was install a bunch of vscode extensions into my jamfadmin home directory. Morning coffee reminded me that I can just package up those extension folders and deploy them via policy, which worked.

View solution in original post