Setting Default Open With for File Types

Not sure what you mean. When I remove import Foundation I get exactly the same errors.

What happens when you replace import Foundation with import Cocoa ?

I get this error instead... Which seems to indicate that Foundation's module isn't missing after all? So strange...

Playground execution failed: Test KM.playground:1:8: error: no such module 'Cocoa'

import Cocoa

** ^**

Have you created an iOS or tvOS Playground? You need a macOS Playground.

52-pty-fs8

Had mistakenly chosen iOS... Getting a different error now, thanks so much for helping!

Playground execution failed: test playground mac.playground:4:68: error: type 'LSRolesMask' has no member 'all'

LSSetDefaultRoleHandlerForContentType("com.adobe.pdf" as CFString, LSRolesMask.all, "com.adobe.Acrobat.Pro" as CFString)

** ^~~~~~~~~~~ ~~~**

** ^~~~~~~~~~~ ~~~**

??

In your Playground with the script code, when you ⌘-right-click the word “LSRolesMask”, do you then get this…

(Note the possible members: none, viewer, editor, shell, all)

…or something different?

You can also try it with LSRolesMask.editor instead of LSRolesMask.all.

Hah, this solved it! My members are all capitalized, so as soon as i changed it to .All (vs .all) it worked! Probably a different version of the library, right?

Thank you so much for sticking with me here, hope this helps debug the issue for others in the future too!

Well, with “All” (instead of “all”) I get this:

Playground execution failed:

error: _Tmp.playground:3:80: error: 'All' has been renamed to 'all'
[…]
CoreServices.LSRolesMask:21:23: note: 'All' was obsoleted in Swift 3


So, you are using Swift 2 (or even 1) ?!

What is your Xcode version?

Not a Swift/Xcode guy, really. Xcode Version 7.3 (7D175) is what I have and capitalizing the A fixed it for me both on Xcode Playground and on KM!

Xcode 7 is from 2015(!), and your Swift then is Swift 2. The current Swift is 4.2!

Assuming you have a more or less recent macOS, then you really should update Xcode. Can be done via the Mac App Store, right from the  menu.

Otherwise you’ll run into lots of similar problems, each time you want to use a Swift script. There have been quite some changes since Swift 2.

Hah. Will do that, thanks again Tom :slight_smile: