Posted on 04-11-2018 05:39 AM
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
Posted on 04-11-2018 06:33 AM
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)...
Posted on 04-11-2018 06:39 AM
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?
Posted on 04-11-2018 06:55 AM
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 :-)
Posted on 04-11-2018 07:50 AM
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.
Posted on 04-11-2018 07:58 AM
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
Posted on 04-11-2018 08:08 AM
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?
Posted on 04-18-2018 07:10 AM
I ran it locally and no error.
Posted on 04-18-2018 07:11 AM
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
Posted on 04-19-2018 01:03 AM
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!
Posted on 04-26-2018 01:18 PM
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.
Posted on 04-27-2018 02:11 AM
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
Posted on 04-27-2018 06:08 AM
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 + "
");')'
Posted on 05-02-2018 04:11 AM
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!
Posted on 05-02-2018 11:33 AM
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 + "
");')'
Posted on 05-03-2018 01:51 AM
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.
Posted on 05-03-2018 08:57 AM
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.
Posted on 05-03-2018 08:59 AM
This happens on all machines.
Posted on 05-03-2018 09:04 AM
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})
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
Posted on 05-03-2018 09:22 AM
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.
Posted on 05-03-2018 10:12 AM
no and running on 10.13.4
Posted on 05-03-2018 10:13 AM
Posted on 05-03-2018 10:29 AM
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
Posted on 05-03-2018 12:22 PM
@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.
Posted on 05-03-2018 01:15 PM
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
Posted on 05-03-2018 01:32 PM
I’m using stand alone. I know that both versions support the add-ins.
Posted on 05-07-2018 06:57 PM
@cddwyer Any other ideas I’m at a lose why this doesn’t work?
Posted on 05-09-2018 12:47 PM
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
Posted on 05-10-2018 07:46 AM
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.