📜 ⬆️ ⬇️

Safari - view the source code of the page in TextMate

Most Safari users who, for one reason or another, view the source code of pages (View Source), feel some inconveniences due to the lack of syntax highlighting. There are several ways to deal with this problem. I will focus, in my opinion, on the most interesting. Personally, I find it most convenient to view the code in the same editor in which I work daily - TextMate.

Task: when clicking a certain Shortcut, display the source code of the page in TextMate
  1. Launch Automator.
  2. As a template (Template for Your Workflow) choose Service
  3. From the list of available actions (Actions), select Run AppleScript and drag it to the workspace.
  4. As input parameter, select no input - this will allow us to start the service without performing additional actions, for example, without selecting a text fragment.
  5. Select the application from which this service will be available. You can choose nothing and then the service will be called, for example in Firefox. I was directly interested in Safari, so I chose him in the drop-down list.

    image

  6. Listing the source code of our AppleScript:
    tell application "Safari" to set theSource to source of document 1

    -- saving it to a file seems to be needed to get TextMate to do color coding
    set fp to open for access "Macintosh HD:tmp:TextMate temp file.txt" with write permission
    write theSource to fp
    close access fp

    -- open the temp file in TextMate
    tell application "TextMate"
    activate
    open "Macintosh HD:tmp:TextMate temp file.txt"
    end tell

  7. Save the service (File-> Save As) and assign it any name, for example View Source in TextMate.
  8. The case remains for small - to assign a key combination for our service. Go to System Preferences -> Keyboard -> Keyboard Shortcuts
  9. In the left pane, select Services.
  10. In the right pane, select our service, which should be located in the General section.
  11. Double-click to the right of the service name will allow you to assign a key combination. You can use something like Cmd + U, then the Shortcut will be the same as in Firefox
    ')
    image

You can try to use instead of TextMate any other editor, who likes what. To do this, you will need to edit the AppleScript code.
This is probably all. I hope to be useful.

Source: https://habr.com/ru/post/90327/


All Articles