Home > database >  How to deeplink a file from macOS app to browser print preview (like sublime text does)?
How to deeplink a file from macOS app to browser print preview (like sublime text does)?

Time:04-21

The functionality I'm after is where Sublime Text opens the browser to the print preview of the file currently edited.
This is the following:

  1. Have a txt file (in sublime).
  2. Select File > Print
    Sublime Text Print
  3. Observe that the default browser opens up to the print preview page (tested in firefox and safari)
    Safari

The urls seem to point to the file being in a temp directory and generated as a html file.
file:///private/var/folders/05/q2p__63n3zx9k3yzcb8f9n0c0000gn/T/tmpbfkdzvmq.html
Note html generation isn't necessary for my use case, remaining as txt is fine.

The answer can be for either swift or objective-c. I'm after how to open the browser to print preview.

CodePudding user response:

I believe the answer involves using Apple Events as mentioned by @Willeke. These is the information I found that assisted me:

In pseudo AppleScript code, it would be something like this:

tell default browser
    launch
    print document
endtell
  • Related