Set Acrobat Reader DC As the Default PDF Handler?

Ecco_Luke
Contributor II

Hi,

I've built a configuration profile with the above preference set on one of our Macs, then uploaded the launcservices plist from it into the profile payload (omitting anything unrelated to Adobe) and deployed that to another test Mac to confirm it works - but PDFs still open in Preview. I've checked and re-checked the plist, and it matches the Mac that does open them in Acrobat Reader DC where relevant.

Is there a way to achieve this, besides using Duti (the current build of which I believe doesn't even work under Mojave)?

2 ACCEPTED SOLUTIONS

dsavageED
Contributor III

We opted to use a python command, so if the user installs acrobat pro it takes over pdf handling, the same would work for another app...

# Acrobat Pro
python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.Acrobat.Pro")'

#Acrobat Reader
python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.reader")'

View solution in original post

dsavageED
Contributor III

@Ecco_Luke - That sounds about right, how are you actually running the code, is it inside a script or using files and processes?

In either case I believe these will be run as root. I have the code inside a script, which does other configuration, so:

#!/bin/sh

UserName=`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 + "
");'`

sudo -u ${UserName} python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.reader")'

but you might be able to use the jamf defined variable for username which is $3:

sudo -u ${3} python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.reader")'

View solution in original post

16 REPLIES 16

grecopj
Contributor

What level are you setting the profile to? Computer or User?

Ecco_Luke
Contributor II

User level, then logging out/back in before testing.

dsavageED
Contributor III

We opted to use a python command, so if the user installs acrobat pro it takes over pdf handling, the same would work for another app...

# Acrobat Pro
python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.Acrobat.Pro")'

#Acrobat Reader
python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.reader")'

Ecco_Luke
Contributor II

I've pasted the plist contents here, just to check I haven't missed anything.

<plist version="1.0">
<dict>
    <key>LSHandlers</key>
    <array>
        <dict>
            <key>LSHandlerPreferredVersions</key>
            <dict>
                <key>LSHandlerRoleAll</key>
                <string>-</string>
            </dict>
            <key>LSHandlerRoleAll</key>
            <string>com.adobe.reader</string>
            <key>LSHandlerURLScheme</key>
            <string>acrobat2018</string>
        </dict>
        <dict>
            <key>LSHandlerContentType</key>
            <string>com.adobe.pdf</string>
            <key>LSHandlerPreferredVersions</key>
            <dict>
                <key>LSHandlerRoleAll</key>
                <string>-</string>
            </dict>
            <key>LSHandlerRoleAll</key>
            <string>com.adobe.reader</string>
        </dict>
    </array>
</dict>
</plist>

Ecco_Luke
Contributor II

The Python command works great, thanks for that! I just saw you've added a version for Reader - I'd already amended your original on our end but thanks a lot for the follow-up! :)

Ecco_Luke
Contributor II

@dsavageED - It seems to work if I run it locally on the test Mac but not via policy. The trigger is recurring check-in and the frequency is set to 'Once per user' (it's a multi-user computer and the preference needs to be global). Does that sound right?

dsavageED
Contributor III

@Ecco_Luke - That sounds about right, how are you actually running the code, is it inside a script or using files and processes?

In either case I believe these will be run as root. I have the code inside a script, which does other configuration, so:

#!/bin/sh

UserName=`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 + "
");'`

sudo -u ${UserName} python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.reader")'

but you might be able to use the jamf defined variable for username which is $3:

sudo -u ${3} python -c 'from LaunchServices import LSSetDefaultRoleHandlerForContentType; LSSetDefaultRoleHandlerForContentType("com.adobe.pdf", 0x00000002, "com.adobe.reader")'

Ecco_Luke
Contributor II

Thanks, @dsavageED. Would that first script run as-is (not the one with the Jamf-defined username variable)? If so, I can test that by replacing my current script with it.

dsavageED
Contributor III

It should do, yes. If you run into an issue, try using /usr/bin/python rather than just python, sometimes the shell can be a bit weird...

Ecco_Luke
Contributor II

Thanks, I'll try that and report back!

Ecco_Luke
Contributor II

It seems to work on one user account but not on any others. It shouldn't matter that not all of the accounts on the computer have admin privileges I assume?

dsavageED
Contributor III

No it shouldn't. The setting is at a user level, so the user will always have rights to their own Library. What is your check-in frequency?

Ecco_Luke
Contributor II

Every 15 minutes. I've also checked the plist for the user account it's not working on but that reads as Reader being set as the default PDF handler... so I'm even more confused!

Ecco_Luke
Contributor II

@dsavageED This has worked on another account that I hadn't yet tampered with, whereas the other account had been altered quite a bit.

dng2000
Contributor II

This doesn't seem to work with python3.

mdcooledge
New Contributor III

Any luck getting this to work with python3?