Posted on 06-03-2016 02:27 AM
I've been asked to report on users who have iCloud Drive enabled.
I found an older EA on the board but that doesn't seem to work on El Cap even if I amend the file path.
This is what i'm using.
iCloudDriveFolder="~/Library/Mobile Documents/com~apple~CloudDocs"
if [ -e "${iCloudDriveFolder}" ]; then
echo "<result>Enabled</result>"
else
echo "<result>Disabled</result>"
fi
Seems to be that the ~/Library/Mobile Documents/com~apple~CloudDocs isn't recognised using the above. I can cd to the folder and terminal sees it as a directory.
Now am i missing something or is it something else?
Thanks
Al
Solved! Go to Solution.
Posted on 06-03-2016 03:57 AM
Two important characters got lost after the copy and paste of my script :)
#!/bin/bash
MobileDocsCount=`ls -l /Users/*/Library/ | grep "Mobile Documents" | wc -l | sed 's/ //g'`
echo "<result>$MobileDocsCount</result>"
Posted on 06-03-2016 03:21 AM
I'm using the following to count the number of local iCloud drives of all local users on a machine.
MobileDocsCount=ls -l /Users/*/Library/ | grep "Mobile Documents" | wc -l | sed 's/ //g'
echo "<result>$MobileDocsCount</result>"
Posted on 06-03-2016 03:51 AM
Thanks @macbofh
Looks good but for some reason it's not giving me any output on a Mac that definitely has drive setup.
Any ideas?
Posted on 06-03-2016 03:57 AM
Two important characters got lost after the copy and paste of my script :)
#!/bin/bash
MobileDocsCount=`ls -l /Users/*/Library/ | grep "Mobile Documents" | wc -l | sed 's/ //g'`
echo "<result>$MobileDocsCount</result>"
Posted on 06-03-2016 04:03 AM
Ah Ha! Seems to have done the trick..
Thank you.
Posted on 09-05-2018 03:19 AM
Your extension works perfectly in 10.12 and older. In 10.13 the Mobile Documents folder is standard and visible.
Here's an updated version:
#!/bin/bash
MobileDocsCount=$(ls -l "/Users/*/Library/Mobile Documents" | grep "com~apple~CloudDocs" | wc -l | sed 's/ //g')
echo "<result>${MobileDocsCount}</result>"
Posted on 03-14-2019 09:32 AM
The suggestion iMathjis made not working for me on High Sierra. It is working if running from terminal, but I get 0 in the JAMF pro
Posted on 08-21-2019 08:50 AM
Small edit to make this script work in Mojave (I haven't tested previous OS versions):
#!/bin/bash
MobileDocsCount=$(ls -l /Users/*/Library/Mobile Documents | grep "com~apple~CloudDocs" | wc -l | sed 's/ //g')
echo "<result>${MobileDocsCount}</result>"
Posted on 03-24-2021 12:28 PM
I expanded this because if the Mobile Documents folder exists it doesn't mean iCloud Drive is active. If it is active and you disable it, it removes the folders from within the Mobile Documents folder, but leaves the folder. So you have to consider if the Mobile Documents folder exists, and if it does, does it contain any other folders:
MobileDocsCount=ls -l /Users//Library/"Mobile Documents"/ | wc -l | sed 's/ //g'
MobileDocs=ls -l /Users/
/Library/ | grep "Mobile Documents" | wc -l | sed 's/ //g'
if [ $MobileDocs != 0 ]
then
if [ $MobileDocsCount != 0 ]
then
echo "<result>Enabled</result>"
else
echo "<result>Disabled</result>"
fi
else echo "<result>Disabled</result>"
fi
Posted on 01-19-2022 02:48 PM
The following script is used in our environment but provides a unique output: "2". It is believed that 0 would mean that the folder and its contents were present, while 1 would mean that the folder and its contents were not present. However, I am getting an output "2". Can anyone provide some insight?
#!/bin/bash
MobileDocsCount=`ls -l /Users/*/Library/ | grep "Mobile Documents" | wc -l | sed 's/ //g'`
echo "<result>$MobileDocsCount</result>"
Posted on 01-20-2022 05:48 PM
Hey @fernandez_payen,
If you are getting 2 as the output of that command, that means there is more than one folder in /Users/*/Library/ that contains the words "Mobile Documents".
This could mean that multiple users on the device have that folder present or there are multiple folders in one user's ~/Library/ that contains the words "Mobile Documents". eg. ~/Library/"Mobile Documents"/ and ~/Library/"New Mobile Documents"/.
The wc utility displays the number of lines, words, and bytes contained in each input file, or standard input. This means it is not reporting if the command succeeded or failed but is actually returning a count of how many occurrences of "Mobile Documents" was found
I have been testing this on Monterey and this is the EA we are using. Note that we a looking at less than or equal to 1 for $MobileDocsCount. This is because on Monterey when you ls -l a folder it will return a single line stating total 0.
Additionally we are a 1:1 deployment so this may not work for a 1:many.
#!/bin/zsh
MobileDocsCount=$(ls -l /Users/*/Library/"Mobile Documents"/ | wc -l | sed 's/ //g')
MobileDocs=$(ls -l /Users/*/Library/ | grep "Mobile Documents" | wc -l | sed 's/ //g')
if [ $MobileDocs != 0 ]; then
if [ $MobileDocsCount -le 1 ]; then
echo "<result>Disabled</result>"
else
echo "<result>Enabled</result>"
fi
else
echo "<result>Disabled</result>"
fi