Unlink OneDrive script help

Jens_Mansson
New Contributor

We have a situation with the tenant for onedrive and to rebuild the tenant(sadly only solution) we must ensure that all users unlink their accounts, simply disable onedrive is not an option.
Can this be done with applescript or if someone knows some other tool that might be of use? Any tips are welcome!

3 REPLIES 3

Jens_Mansson
New Contributor

I've tried doing Automator to Applescript but it doesn't click on the last "Unlink Account" as displayed in the picture, as if the script doesnt accept the last ui element.
Anyone good at Applescript? Only option left is to manually unlink for all users.

c9eebf9cbaed4a9c9e82151d3985d8da

-- Click the menu bar item.
delay 1.536848
set timeoutSeconds to 2.0
set uiScript to "click menu bar item 1 of menu bar 2 of application process "OneDrive""
my doWithTimeout(uiScript, timeoutSeconds)

-- Preferences...
delay 1.1103
set timeoutSeconds to 2.0
set uiScript to "click menu item "Preferences..." of menu 1 of menu bar item 1 of menu bar 2 of application process "OneDrive""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “Account” toolbar button.
delay 2.004864
set timeoutSeconds to 2.0
set uiScript to "click UI Element "Account" of tool bar 1 of window "General" of application process "OneDrive""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “Unlink Account” button.
delay 1.904296
set timeoutSeconds to 2.0
set uiScript to "click UI Element "Unlink Account" of group 1 of window "Account" of application process "OneDrive""
my doWithTimeout(uiScript, timeoutSeconds)

-- Click the “Unlink Account” button.
delay 1.547241
set timeoutSeconds to 2.0
set uiScript to "click UI Element "Unlink Account" of window 1 of application process "OneDrive""
my doWithTimeout(uiScript, timeoutSeconds)

on doWithTimeout(uiScript, timeoutSeconds)
    set endDate to (current date) + timeoutSeconds
    repeat
        try
            run script "tell application "System Events"
" & uiScript & "
end tell"
            exit repeat
        on error errorMessage
            if ((current date) > endDate) then
                error "Can not " & uiScript
            end if
        end try
    end repeat
end doWithTimeout

bpavlov
Honored Contributor

@Jens.Mansson A member of the OneDrive team just recently joined Slack and might be a good resource to ask about this. I'd recommend joining the #microsoft-office channel and asking there as well. I already forwarded a link to this discussion to the person in question too just in case.

http://macadmins.org/

Mauricio
Contributor III

Just found a plist file at:

~/Library/GroupContainers/UBF8T346G9.OneDriveSyncClientSuite/Library/Preferences/UBF8T346G9.OneDriveSyncClientSuite.plist

which lists my personal and business accounts.
Not done any testing but could be worth a try.

Regards