I changed my script a bit so that it does not rely on $3. It also removes the previous OneDrive container folder which I found can clear up some issues when trying to reinstall.
#!/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 + "
");'`
if [ ! -d /Applications/OneDrive.app/ ];then
echo "OneDrive app not installed"
exit 0
fi
if [ -d /Users/$loggedInUser/Library/Containers/com.microsoft.OneDrive-mac/ ];then
rm -R /Users/$loggedInUser/Library/Containers/com.microsoft.OneDrive-mac/
echo "Removed existing com.microsoft.OneDrive-mac container"
fi
defaults write /Users/$loggedInUser/Library/Preferences/com.microsoft.OneDrive-mac DefaultToBusinessFRE -bool True
defaults write /Users/$loggedInUser/Library/Preferences/com.microsoft.OneDrive-mac EnableAddAccounts -bool True
chown $loggedInUser /Users/$loggedInUser/Library/Preferences/com.microsoft.OneDrive-mac.plist
su -l $loggedInUser -c "open /Applications/OneDrive.app/"
going to try it. Thanks!!
@cbrewer
Thank you !!! Thank you !!!!
C
@stpetersgirls Did you ever get this to work? I want to have a preset location for users as well instead of letting them pick their own. if you could post script or example how you accomplished this would be great. thanks!
I thought I'd add my 2 cents to this post.
I'm currently working on packaging and testing the OneDrive deployment. I started out with a script that would configure the client, similar to cbrewer. Then I decided to just use Composer to package the plist file and saved it as a DMG and set FUT/FEU option. This way, if other users log in after OneDrive has been installed, they would have the same "Business Account" settings.
One thing that I haven't been able to figure out is how to enable the Finder Extension for OneDrive. (In System Preferences, Extensions) Has anyone had any luck with this?
Couldn't find which plist/sqlite db etc was controlling the enabled/disabled flag for OneDrive Finder Extension so went down the applescript route.
Not my preferred method but it gets the job done.
@Retrac would you mind posting script? I am also trying to do same thing.
Sure @wmateo,
This is what I am running in the Self Service policy on the after priority.
#!/bin/sh
#Get the logged in user
LoggedInUser=`who | grep console | awk '{print $1}'`
echo "Current user is $LoggedInUser"
#Get OS version to determine how to allow assistive access
osvers=$(sw_vers -productVersion | awk -F. '{print $2}')
echo "Running OS is 10.$osvers"
#Give jamfagent access to be an assistive device for osascript
if [[ "$osvers" == "11" ]];then
sqlite3 /Library/Application Support/com.apple.TCC/TCC.db "INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','/usr/local/jamf/bin/jamfAgent',1,1,1,NULL,NULL)"
echo "jamfAgent given access as assistive device on OSX 10.11.x"
fi
if [[ "$osvers" == "9" || "$osvers" == "10" ]]; then
sqlite3 /Library/Application Support/com.apple.TCC/TCC.db "INSERT or REPLACE INTO access VALUES('kTCCServiceAccessibility','/usr/local/jamf/bin/jamfAgent',1,1,1,NULL)"
echo "jamfAgent given access as assistive device on OSX 10.9/10"
fi
su - $LoggedInUser -c /usr/bin/osascript <<Runit
tell application "System Preferences"
activate
set the current pane to pane id "com.apple.preferences.extensions"
delay 0.5
end tell
tell application "System Events" to tell process "System Preferences"
delay 0.5
select row 3 of table 1 of scroll area 1 of window "Extensions"
end tell
tell application "System Events"
tell application process "System Preferences"
--repeat while not (rows of table 1 of scroll area 1 of group 1 of window 1 exists)
repeat while not (window "Extensions" exists)
end repeat
tell window "Extensions"
repeat while not (rows of table 1 of scroll area of group 1 exists)
end repeat
set the_row to "1"
repeat with current_row in (rows of table 1 of scroll area 1 of group 1)
if value of static text 1 of UI element 1 of current_row is equal to "OneDrive Finder Integration" then
--select current_row
if value of checkbox 1 of UI element 1 of current_row is 0 then click checkbox 1 of UI element 1 of current_row
--click checkbox 1 of UI element 1 of current_row is equal to "OneDrive Finder Integration"
exit repeat
end if
end repeat
end tell
end tell
end tell
delay 0.5
quit application "System Preferences"
Runit
echo "OneDrive Finder integration enabled"
#Remove assistive device access
sqlite3 /Library/Application Support/com.apple.TCC/TCC.db "delete from access where client='/usr/local/jamf/bin/jamfAgent';"
echo "jamfAgent assistive access removed"
exit 0
pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync
will enable the Finder extension for the current user
Chris,
Thank you SO MUCH!!! I've been looking all over the web to find something like this. I even opened a call with Apple to see if they knew of a command line tool. They couldn't help.
Anyways, this is perfect. Thanks!
Hi All,
If anyone is interested, it appears that the preferences for OneDrive are written here:
/Users/username/Library/Group Containers/sync.com.microsoft.OneDrive-mac/Library/Preferences/sync.com.microsoft.OneDrive-mac.plist
So with this in mind, this is the script I'm putting into self service to allow my staff to configure OneDrive:
#!/bin/bash
# Define Username Variable
username=$(ls -l /dev/console | awk '{print $3}')
# If OneDrive App has not been successfully installed, the script will not run.
if [ ! -d /Applications/OneDrive.app/ ];then
echo "OneDrive app not installed"
exit 0
fi
# Set OneDrive Preferences
su -l $username -c "defaults write com.microsoft.OneDrive-mac DefaultToBusinessFRE -bool True"
su -l $username -c "defaults write com.microsoft.OneDrive-mac EnableAddAccounts -bool True"
# Enable OneDrive Finder Extensions
pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync
# Boot OneDrive Application
su -l $username -c "open /Applications/OneDrive.app/"
Thanks to all of those who have given wisdom and help on this project!! :-)
I saw this question asked before, but I wanted to ask it again, has anyone been able to script the "open at login" option?
Thanks!
Tim
Hey All,
So I ran the pluginkit command above as the user, and it does indeed check the box in Sys Pref -> Extensions. But I do not see the OneDrive folder name show up under Favorites in the Finder Sidebar. Isn't that what that Extension is for. I thought maybe it was cuase I ran the command, but I imaged a fresh machine and manually checked it and got the same result. Is there a character limit on the name that can show up in Favorites. Maybe our company is well over it. ?
Thanks for your guys/gals input!
Shawn
mine is pretty simple but it creates all the plists and edits them first. then just opens the app store to the one drive app for them to install. Once they open it they are directed to 365 login. For some reason this line in the script doesn't actually set the permissions properly so i placed it as Files and Commands execute command
sudo chown -f $USER ~/Library/Containers/com.microsoft.OneDrive-mac/Data/Library/Preferences/com.microsoft.OneDrive-mac.plist
!/bin/sh
touch ~/Library/Containers/com.microsoft.OneDrive-mac/Data/Library/Preferences/com.microsoft.OneDrive-mac.plist
sudo chown -R $USER ~/Library/Containers/com.microsoft.OneDrive-mac/
sudo chown -f $USER ~/Library/Containers/com.microsoft.OneDrive-mac/Data/Library/Preferences/com.microsoft.OneDrive-mac.plist
defaults write ~/Library/Containers/com.microsoft.OneDrive-mac/Data/Library/Preferences/com.microsoft.OneDrive-mac DefaultToBusinessFRE -bool True
defaults write ~/Library/Containers/com.microsoft.OneDrive-mac/Data/Library/Preferences/com.microsoft.OneDrive-mac DisablePersonalSync -bool True
open 'macappstores://itunes.apple.com/au/app/onedrive/id823766827?mt=12'
Hi @cbrewer
I'm wondering if you've found any clever method of firing off your plist edit script after your Self Service VPP installs. I'm struggling with how to do this right now. I can have techs manually run each self service policy in order on newly deployed machines, but I'm worried about all the existing users. Having them run each policy in order is gonna be a nightmare! :)
And yes, definitely feature requesting a way to at least trigger a policy if not bundle scripts in with the VPP self service items!
Thanks,
mbezzo
FYI, looks like a Feature request was created for this: https://jamfnation.jamfsoftware.com/featureRequest.html?id=2862
@sgoetz The Finder extension for OneDrive when enabled allows you to see the little ticks and crosses on the files/folders.
You can drag the OneDrive @ Business folder to the sidebar and it will stick.
Once the finder is reloaded the sidebar will also display OneDrive as a cloud icon rather than a folder.
Can anyone confirm if One Drive currently supports an on-prem solution?
@fritz.schlapbach back in December said it doesn't...
I've benefited from this thread so I thought I'd post back what I've come up with for configuring OneDrive for Business, in case it helps anyone else:
I used this plist used to create a Custom Config profile in the JSS to:
-Enable OneDrive for Business
-Block Personal OneDrive
-Allow user to add account
per MS Documentation
Preference Domain: com.microsoft.OneDrive-mac
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DefaultToBusinessFRE</key>
<true/>
<key>DisablePersonalSync</key>
<true/>
<key>EnableAddAccounts</key>
<true/>
</dict>
</plist>
Launch Agent to open OneDrive at every login for every user, placed in /Library/LaunchAgents
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.merrill.LaunchOneDrive</string>
<key>Program</key>
<string>/Applications/OneDrive.app/Contents/MacOS/OneDrive</string>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
This is a portion of a script to enable the OneDrive Finder Extension and add OneDrive to user's sidebar using mysides . This script is called by a LaunchAgent that is installed into each user's ~/Library/LaunchAgents (and the user template), then the LaunchAgent for that user is deleted at the end of the script so it only runs once for each 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 + "
");'`
pluginkit -e use -i com.microsoft.OneDrive-mac.FinderSync
/PathToMySides/mysides add OneDrive file:///Users/$loggedInUser/YourOneDriveDirectoryName
rm ~/Library/LaunchAgents/com.YourLaunchAgentName.plist
@Josh.Smith
Thank you and I will be using your Custom Config profile : ) : )
C
@Retrac did you ever figure out the open at Login? might just use it as a launch agent
Did anyone manage to script the default folder location for OneDrive using PlistBuddy as per MS documentation? Or via some other way?
Unfortunately we are not going down the 365 path @wmateo so my development of using OneDrive has come to a halt.
@wmateo I couldn't figure out how to manage the Open at Login functionality in the App and just created a Launch Agent. I looked through all of the plists and tried running captures with Composer (new and modified as well as monitor file system) to pickup the change, but couldn't track it down.
I can't think of a use case where a user would need to disable it, so I was ok with overriding the setting in the GUI. The app launches at login regardless of the app setting now....if there is no network connection OneDrive just sits quietly waiting for one.