Skip to main content
Solved

Set Acrobat Reader DC As the Default PDF Handler?

  • November 2, 2018
  • 16 replies
  • 71 views

Ecco_Luke
Forum|alt.badge.img+8

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)?

Best answer by dsavageED

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")'

16 replies

grecopj
Forum|alt.badge.img+8
  • Valued Contributor
  • November 2, 2018

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


Ecco_Luke
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 2, 2018

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


dsavageED
Forum|alt.badge.img+8
  • New Contributor
  • Answer
  • November 2, 2018

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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 2, 2018

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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 2, 2018

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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 6, 2018

@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
Forum|alt.badge.img+8
  • New Contributor
  • November 6, 2018

@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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 6, 2018

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
Forum|alt.badge.img+8
  • New Contributor
  • November 6, 2018

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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 6, 2018

Thanks, I'll try that and report back!


Ecco_Luke
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 6, 2018

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
Forum|alt.badge.img+8
  • New Contributor
  • November 6, 2018

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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 6, 2018

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
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 6, 2018

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


Forum|alt.badge.img+11
  • Valued Contributor
  • April 6, 2023

This doesn't seem to work with python3.


Forum|alt.badge.img+4
  • Contributor
  • September 28, 2023

This doesn't seem to work with python3.


Any luck getting this to work with python3?