-2

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.

Patrick
  • 2,035
  • 17
  • 27
  • 1
    What is the question? How to open a file in the default browser? How to tell the default browser to print? Did you try anything? – Willeke Apr 17 '22 at 20:27
  • "The urls seem to point to the file being in a temp directory" Which URLs? – Alexander Apr 17 '22 at 21:53
  • The question is how to open a browser to the print preview page for a file that was generated inside a macOS app, ie a text file. The URL displayed in the browser. – Patrick Apr 18 '22 at 05:01
  • Does this answer your question? [OSX Swift open URL in default browser](https://stackoverflow.com/questions/26704852/osx-swift-open-url-in-default-browser) – Willeke Apr 18 '22 at 10:19
  • Safari opens the Print dialog when it receives a Print Apple Event. – Willeke Apr 18 '22 at 13:39
  • Regarding that link @Willeke, what I'm after is the url scheme to get the OS to trigger the browser to show the print dialog. I can trigger a link and have the browser open no problem, but what does the url need to contain to inform the browser to open the print dialog? Regarding the Print Apple Event, I will look into this. – Patrick Apr 19 '22 at 11:30

1 Answers1

0

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
Patrick
  • 2,035
  • 17
  • 27