Skip to content

Use browser as viewer on MacΒ #1371

@zsiegel92

Description

@zsiegel92

Hi,

Using your browser as a viewer on a Mac is as easy as changing the settings to

"viewer": "command",
"viewer_settings": {
		// Platform-specific settings:
		"osx" : {
			"view_command":"open -a 'Google Chrome' $pdf_file"
		}
	}

But this, unfortunately, always opens a new tab with the pdf (on every build!), which is not remotely similar to the experience of using a dedicated Tex builder/viewer.

I propose instead using the following command:

"osx" : {
			"view_command":"osascript /Users/username/Library/Scripts/OpenFileInChrome.applescript $pdf_file"
		}

where /Users/username/Library/Scripts/ is your preferred applescripts folder, containing the following script OpenFileInChrome.applescript:

on run argv
	set theFile to item 1 of argv
	set pdfName to theFile
	tell application "Google Chrome"
		activate
		set found to false
		set windowList to every window
		repeat with aWindow in windowList
			set tabList to every tab of aWindow
			set tabIndex to 0
			repeat with atab in tabList
				set tabIndex to tabIndex + 1
				if (URL of atab contains pdfName) then
					set found to true
					tell atab to reload
					set aWindow's active tab index to tabIndex
					set index of aWindow to 1
				end if
			end repeat
		end repeat
		if not found then
			set str to "open -a 'Google Chrome' " & pdfName
			do shell script str
		end if
	end tell
end run

This script makes sure to open the file in the tab it is already open in, and to reload it to reflect built changes. If the file is not open, it simply opens it in a new tab/window (per your default Chrome settings).

This script is the feature that allows me to use LaTeXTools as opposed to TeXShop.

If it were possible for a Chrome extension to achieve bi-directional, sync, that would be great...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions