OneDrive Enable Extension erro

KyleEricson
Valued Contributor

This is the error I get:

Running script OneDrive Finder Extension...
Script exit code: 1
Script result: match: Connection invalid
Error running script: return code was 1.

This is my script:

#!/bin/sh
loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

#enables Finder Extension for current user
pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync
28 REPLIES 28

Jesper
New Contributor III

I messed around with this as well, however never found a workable solution.

It is something to do with the context you run your script in. You have to run it as the user being logged in, if I understand it correctly. (I might not)...

KyleEricson
Valued Contributor

Can't you have JAMF run scripts as login user or could this be added via composer to a .pkg file as post install script?

Jesper
New Contributor III

I honestly dont know. Which is why I never found a workable solution.
I can see you have read the same thread that I did. So you have the same info as me.

Cant really offer more than this, just wanted to point you in a direction...
Ill monitor this thread in hopes that someone will provide better advice πŸ™‚

cddwyer
Contributor

You're obtaining the logged in user's name and putting into a variable but then never using the variable.

To run this in the logged in user context the script should be:

#!/bin/sh

loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

#enables Finder Extension for current user
su $loggedInUser -c 'pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync'

exit 0

Hope that helps.

KyleEricson
Valued Contributor

I changed it and I get this error now.

Script result: 2018-04-11 09:55:47.699 pluginkit[21325:8247234] Communications error: <OS_xpc_error: <error: 0x108e19c90> { count = 1, contents = "XPCErrorDescription" => <string: 0x108e19f78> { length = 18, contents = "Connection invalid" }
}>
match: Connection invalid

cddwyer
Contributor

That looks like an error from your command. If you run the original command in Terminal when logged in as the current user manually do you receive the same error?

KyleEricson
Valued Contributor

I ran it locally and no error.

KyleEricson
Valued Contributor

My script

#!/bin/sh

loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

#enables Finder Extension for current user
su $loggedInUser -c 'pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync'

exit 0

cddwyer
Contributor

OK, I have run into certain scripts that when run through Jamf error and never seemed to get to the bottom of it. However, you can work around it by modifying your Jamf script to this:

#!/bin/sh

#Create empty file in temp directory
touch /tmp/script1.sh

#Write the script we actually want to run locally into the file
echo '#!/bin/sh

loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

#enables Finder Extension for current user
su $loggedInUser -c 'pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync'

exit 0' > /tmp/script1.sh

#Make the script executable 
chmod a+x /tmp/script1.sh

#Run the script
/bin/sh /tmp/script1.sh

#If shell exit code was not 0, inform of error
if [ $? -ne 0 ]; then
   echo "Script exited with an error!"
fi

#Delete script from temp folder
rm -f /tmp/script1.sh

exit 0

This way you create the script locally, run it, then delete it again.

I hope that helps!

KyleEricson
Valued Contributor

Fails

Executing Policy OneDrive Extension enable
Running script OneDrive 2.0...
Script exit code: 2
Script result: /Library/Application Support/JAMF/tmp/OneDrive 2.0: line 9: syntax error near unexpected token `('
/Library/Application Support/JAMF/tmp/OneDrive 2.0: line 9: loggedInUser=python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");'`'

Error running script: return code was 2.

cddwyer
Contributor

OK try this modified version. It's in bash instead of shell which is a bit more forgiving, I've also changed the syntax of the command that errored.

I'd be shocked if this didn't work!...

Good luck.

#!/bin/bash

#Create empty file in temp directory
touch /tmp/script1.sh

#Write the script we actually want to run locally into the file
echo '#!/bin/bash

loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

#enables Finder Extension for current user
su $loggedInUser -c 'pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync'

exit 0' > /tmp/script1.sh

#Make the script executable 
chmod a+x /tmp/script1.sh

#Run the script
/bin/bash /tmp/script1.sh

#If bash exit code was not 0, inform of error
if [ $? -ne 0 ]; then
   echo "Script exited with an error!"
fi

#Delete script from temp folder
rm -f /tmp/script1.sh

exit 0

KyleEricson
Valued Contributor

New error: Script result: /Library/Application Support/JAMF/tmp/OneDrive 2.0: line 9: syntax error near unexpected token `('
/Library/Application Support/JAMF/tmp/OneDrive 2.0: line 9: `loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')'

cddwyer
Contributor

OK that's weird, I think I know what might be happening though, sometimes copied and pasted text from websites into bash scripts have incorrectly replaced unicode characters in, meaning there might be two different ( symbols, but only one is recognised by the shell.

To fix this, download and/or open Text Wrangler, paste my script in there, then goto the 'Text' menu, and select the 'Zap Gremlins' option, this produces a pop-up dialog, ensure the top three boxes are checked under the search for heading, and under the 'and then..' heading, select the 'Replace with code' option and check 'Use ASCII equivalent' box. Then copy the script from Text Wrangler, into Jamf. This should work!

I have my fingers crossed for you!

KyleEricson
Valued Contributor

I tried that and same error:
Script result: /Library/Application Support/JAMF/tmp/OneDrive 2.0: line 9: syntax error near unexpected token `('
/Library/Application Support/JAMF/tmp/OneDrive 2.0: line 9: `loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + " ");')'

cddwyer
Contributor

OK. This is strange. Replace the line beginning with "loggedInUser=$(..." with:

loggedInUser=$(ls -l /dev/console | awk '{print $3}')

I would also strongly recommend that you type that in and do not copy and paste it. (Note there's a capital 'i' and 'u' but a lower case 'L' in 'loggedInUser')

If you get another error, change the she-bang at the top of your script from '#!/bin/bash' to '#!/bin/bash -x' and it will give you more output to paste back here if necessary. Although, if this still doesn't work, depending on the error you may need to flatten this machine, I presume this is happening on one particular machine not all in your estate?

Once again, good luck.

KyleEricson
Valued Contributor

New error.

Executing Policy OneDrive Extension enable
Running script OneDrive 2.0...
Script exit code: 0
Script result: awk: syntax error at source line 1 context is >>> <<< awk: illegal statement at source line 1 missing }
su: illegal option -- c
usage: su [-] [-flm] [login [args]]
Checking for patches...
No patch policies were found.

KyleEricson
Valued Contributor

This happens on all machines.

KyleEricson
Valued Contributor

I got this now

Executing Policy OneDrive Extension enable
Running script OneDrive 2.0...
Script exit code: 0
Script result: touch /tmp/script1.sh
echo '#!/bin/bash

loggedInUser=$(ls -l /dev/console | awk {print' 'kericson})

enables Finder Extension for current user

su $loggedInUser -c pluginkit' -e use -i 'com.microsoft.OneDrive-mac.FinderSync

exit 0'
chmod a+x /tmp/script1.sh
/bin/bash /tmp/script1.sh
awk: syntax error at source line 1 context is >>> <<< awk: illegal statement at source line 1 missing }
su: illegal option -- c
usage: su [-] [-flm] [login [args]]
'[' 0 -ne 0 ']'
rm -f /tmp/script1.sh
+ exit 0

cddwyer
Contributor

Wow. Can you screenshot the script as it is input in your JSS? There must be an incorrect character somewhere, I just tested this on my test lab environment and ran successfully on 10.13, 10.12, 10.11 and 10.10 so I can't see why this wouldn't work providing the correct details are in.

Quick couple of questions..

Do you have a non English language OS or keyboard layout setup on your machine? Also, what OS are you running this against?

Thanks and good luck.

KyleEricson
Valued Contributor

no and running on 10.13.4

KyleEricson
Valued Contributor

84d2ef13590c41ceae814da7e61f68c1

mbezzo
Contributor III

Hi All,
I had an idea on how to use this method from @cddwyer so did a quick re-write which is working well for me:

#!/bin/bash

# Idea from cddwyer on jamfnation: https://www.jamf.com/jamf-nation/discussions/27792/onedrive-enable-extension-erro

# Name of Script
scriptName="script1.sh"

# Create Empty Script
touch /tmp/"$scriptName"

# Create the script lcoally we we want to run
cat << 'EOF' > /tmp/"$scriptName"
#!/bin/bash

# Find the currently logged in user
loggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");')

do the stuff here

exit 0
EOF

# Make the script executable 
chmod a+x /tmp/"$scriptName"

# Run the script
/bin/bash /tmp/"$scriptName"

# If bash exit code was not 0, inform of error
if [ $? -ne 0 ]; then
   echo "Script exited with an error!"
fi

# Delete script from temp folder
rm -f /tmp/"$scriptName"

exit 0

Thanks!
Matt

KyleEricson
Valued Contributor

@mbezzo I tried your idea and back to my original error:

Executing Policy OneDrive Extension enable
Running script OneDrive 2.0...
Script exit code: 0
Script result: match: Connection invalid
Checking for patches...
No patch policies were found.

mbezzo
Contributor III

Are you using the App Store version of OneDrive, or the standalone? I believe the domain com.microsoft.OneDrive-mac is for the App Store version - com.microsoft.OneDrive is for the Stand alone app. It's been a long time since I was dealing with this, but I believe (could be wrong...) that the App Store version doesn't support the Finder add-ins? Only the stand alone version? Worth checking out anyway!

Thanks
Matt

KyleEricson
Valued Contributor

I’m using stand alone. I know that both versions support the add-ins.

KyleEricson
Valued Contributor

@cddwyer Any other ideas I’m at a lose why this doesn’t work?

KyleEricson
Valued Contributor

I think I have finally found a solution via a .pkg file. Testing now.

#!/bin/sh
## postinstall

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

#Get current user
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

#Kill OneDrive
killall OneDrive

#OneDrive app store version
su $loggedInUser -c 'pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync'

#OneDrive standalone version
su $loggedInUser -c 'pluginkit -e use -i com.microsoft.OneDrive.FinderSync'

#Move Plist file
mv /tmp/com.microsoft.OneDriveUpdater.plist /Users/$USER/Library/Preferences/
mv /tmp/com.microsoft.OneDrive.plist /Users/$USER/Library/Preferences/

#Take ownership
chown -R $loggedInUser:staff /Users/$USER/Library/Preferences/com.microsoft.OneDriveUpdater.plist
chown -R $loggedInUser:staff /Users/$USER/Library/Preferences/com.microsoft.OneDrive.plist

#Clear cache
killall cfprefsd

#open OneDrive
su $loggedInUser -c 'open /Applications/OneDrive.app'


exit 0      ## Success
exit 1      ## Failure

KyleEricson
Valued Contributor

After testing looks like AppStore version will not enable via a script only if you run the command locally on the Mac will it work.