Posted on 11-02-2018 07:30 AM
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)?
Solved! Go to Solution.
Posted on 11-02-2018 09:00 AM
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")'
Posted on 11-06-2018 02:37 AM
@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")'
Posted on 11-02-2018 08:48 AM
What level are you setting the profile to? Computer or User?
Posted on 11-02-2018 08:57 AM
User level, then logging out/back in before testing.
Posted on 11-02-2018 09:00 AM
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")'
Posted on 11-02-2018 09:04 AM
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>
Posted on 11-02-2018 09:31 AM
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! :)
Posted on 11-06-2018 02:21 AM
@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?
Posted on 11-06-2018 02:37 AM
@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")'
Posted on 11-06-2018 03:39 AM
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.
Posted on 11-06-2018 03:56 AM
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...
Posted on 11-06-2018 04:56 AM
Thanks, I'll try that and report back!
Posted on 11-06-2018 06:05 AM
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?
Posted on 11-06-2018 06:51 AM
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?
Posted on 11-06-2018 07:07 AM
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!
Posted on 11-06-2018 07:29 AM
@dsavageED This has worked on another account that I hadn't yet tampered with, whereas the other account had been altered quite a bit.
Posted on 04-06-2023 01:28 PM
This doesn't seem to work with python3.
Posted on 09-28-2023 08:47 AM
Any luck getting this to work with python3?