Skype for Business - start at login annoyance

cwaldrip
Valued Contributor

Anyone found a way to prevent SfB from setting itself up for start at login.

I'm exploring this thread as a solution, for now.
https://www.jamf.com/jamf-nation/discussions/8645/script-to-remove-item-from-login-items

As a business level app though I'd think there'd be a better way to manage this PITA 'feature'.

11 REPLIES 11

cwaldrip
Valued Contributor

This is what I ended with... as a kludge

#!/bin/bash

for i in $(dscl /Local/Default -list /Users UniqueID | awk '$2 >= 100 { print $1 }' | grep -v "^_");do
    sudo -u "$i" /usr/bin/osascript -e 'tell application "System Events" to delete login item "Skype for Business"' 2>/dev/null
done

exit

cwaldrip
Valued Contributor

Script works when run with sudo locally. Fails when a script run through a policy though. :-

rats.

mm2270
Legendary Contributor III

It fails because you're telling the script to run the osascript command as each user it locates when searching for user accounts above UID 100 (minus system accounts), but the problem is Applescript commands can only run as the logged in user.
That means it may work for the currently logged in account, but will undoubtedly fail for any other accounts it runs across since none of those other users are logged in.
IOW, you cannot use sudo -u $user <some command> for a user account not actually logged in.

I haven't taken a closer look at this, but I have to believe there is some setting in a plist file, either per account, or some global one that applies to all accounts that can be adjusted to remove that auto login setting. I will need to poke around to see what I can find on that.

donmontalvo
Esteemed Contributor III

Sounds like the same problem F5 has when they try to add items to users' Login Items list, on BIG-IP Mac Edge Client 11.5.4.

We pointed their dev team (via internal contacts) to Apple's guidelines, so far we haven't seen a fix released.

https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters...

Does Apple even want anyone doing this for users? Launch Agent would be a lot better.

Might jump on MacAdmins Slack channel, to let the Microsoft folks know about the issue, maybe they can fast track a fix?

--
https://donmontalvo.com

mm2270
Legendary Contributor III

Looks to me like SfB adds the login item to each user's com.apple.loginitems.plist. At least that's what I'm finding.

@cwaldrip Try this script below. I hacked this together fairly quickly and have only given it a cursory trial run, but it does seem to do the trick.

One thing I noticed however is that the GUI is not updated after running it. Meaning it still shows up in the user's Login Items tab under their account in Users & Groups, but the entry is gone from the plist itself. And yes, I tried all kinds of things, like killall cfprefsd and such, and it had no effect on the UI. I had to do a full reboot to make it disappear. I noted that SfB did not open automatically after rebooting and logging in, so it did actually work.

#!/bin/bash

itemToRemove="Skype for Business"

function Find_Remove_loginItem ()
{

LIPlist="/Users/${i}/Library/Preferences/com.apple.loginitems.plist"

## Check to see if there is a com.apple.loginitems.plist for the user
if [ -e "$LIPlist" ]; then
    ## Build a list of Auto Launch entries by grabbing the Name item from each entry
    ALAppsList=$(/usr/libexec/PlistBuddy -c "Print :SessionItems:CustomListItems:" "$LIPlist" | awk -F'= ' '/Name /{print $NF}')

    ## While looping over each entry, see if it matches the itemToRemove variable defined up above
    x=0
    while read ENTRY; do
        if [ "$ENTRY" == "$itemToRemove" ]; then
            ## If a match is found, set an index variable
            itemIndex="$x"
            echo "Found $itemToRemove entry in plist for ${i} at index $itemIndex. Removing it..."
            ## Delete the entry by its index in the plist, using PlistBuddy
            /usr/libexec/PlistBuddy -c "Delete :SessionItems:CustomListItems:$itemIndex" "$LIPlist"
        fi
        let x=$((x+1))
    done < <(printf '%s
' "$ALAppsList")
fi

}

## Build a list of user accounts to check
for i in $(dscl /Local/Default -list /Users UniqueID | awk '$2 >= 100 { print $1 }' | grep -v "^_");do
    ## For each user, run the function to find and delete the login item
    Find_Remove_loginItem
done

To try to make the script a bit flexible, you can change the itemToRemove variable to some other entry and it should work for those as well.

cwaldrip
Valued Contributor

It looks like ~/Library/Preferences/com.apple.loginitems.plist no longer is the exclusive home of login items.

If I have Skype for Business in the login items 83b9270c25ab4f3bac5dd8c0806e18f6
and then run...

/usr/libexec/PlistBuddy -c "Print :SessionItems:CustomListItems:" /Users/cwaldrip/LIbrary/Preferences/com.apple.loginitems.plist | awk -F'= ' '/Name /{print $NF}'

Skype for Business is NOT included in the list.
- Magnet.app
- gfxCardStatus.app
- iTunesHelper.app
- SMARTReporter.app
- Dropbox.app
- FruitJuice.app
- Synergy.app
- LiveDesktop.app
- Enterprise Connect.app
- Knock.app
- Parallels Toolbox.app
- Caffeine.app
- HazelHelper.app

I tried to capture where it's stored with Composer, but nothing obvious showed up... Suggestions?

mm2270
Legendary Contributor III

Odd. It shows up in my account's loginitems plist file. But in truth, I don't know if I actually added that in myself or if SfB added it itself.
The only other place I can suggest off hand to look would be in the global /Library/Preferences/ for a com.apple.loginitems.plist. It's possible it adds itself there. A few apps we use do that, like Cisco AnyConnect. This means it launches for any user that logs in, not just the one that was logged in when it got installed.

cwaldrip
Valued Contributor

Good idea, so I checked. Not there. I can add/remove it manually in Users & Groups under my account, and it doesn't show up in the plist file. Even tried killall cfprefsd.

I just noticed that one item listed isn't in the plist, and on a hunch I deleted the plist and reopened Users & Groups. Everything was still there. I deleted all the login items in Users & Groups, closed and reopened System Preferences, and went to Users & Groups and it was empty so I added stuff to it and quit System Preferences. The plist file was NOT recreated, but all the items were still there when I reopened Users & Groups.

And /Library/Preferences/com.apple.loginitems.plist is the same thing. Deleted it and it's not recreated.

I'm totally confused now. Apparently that plist has nothing to do with login items anymore? And I can't find where the info is stored now...

cwaldrip
Valued Contributor

I'm not the first to notice the loginitems.plist is worthless...
https://discussions.apple.com/thread/8086931?start=0&tstart=0

cwaldrip
Valued Contributor

This looks like the new home for (some) login items... eyeroll

/var/db/com.apple.xpc.launchd/loginitems.<uid>.plist

Jason
Contributor II

I'm having the opposite problem. If I run SfB manually then it adds to the Login Items (which is what we want). But if I deploy the vanilla package out with JAMF then it doesn't get added there.

Does anyone know of a way to deploy it so that it DOES get added to the Login Items like it would if the user ran it directly?