Sublime Forum

Browser Preview

#1

Hey,
is it possible to preview/open my html/css code from Sublime with an shortcut in a Browser?

0 Likes

#2

If you choose the Tools menu, Build System, New Build System and create this:

{ "cmd": "C:\\Users\\Andrew\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe", "$file"] }

Save this file using the extension ‘sublime-build’ in your User folder. This opens the displayed page in whichever browser you identify. ($file means the current file.)

Then you can run it by choosing Tools, Build System ‘YourNewBuild’. After you’ve used it once. then pressing Ctrl-B should in future cause it to run your build.

I haven’t worked out yet how to assign it to some other shortcut key - perhaps it needs to be converted to a macro or command?

Andy.

0 Likes

#3

Interesting. This seems to work for Mac users:

{
    "cmd": "/Applications/Safari.app/Contents/MacOS/Safari", "$file"]
}

Except it opens the Sublime console and displayed this 3 times:

2012-02-09 16:34:06.860 Safari[64689:707] CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.

Edit: the messages only happend the first time, when Safari launched. Can you prevent the console from opening on a build, though?

0 Likes

#4

Might be better to use “open” command on Mac which should open file in the default browser.
And also add “selector” so that one doesn’t have to change to proper build system manually.

{ "cmd": "open", "$file"], "selector": "text.html, source.html, text.xml", }

0 Likes

#5

Except open would open it in the default app, which I have set to Sublime. Right?

0 Likes

#6

[quote=“rchl”]Might be better to use “open” command on Mac which should open file in the default browser.
And also add “selector” so that one doesn’t have to change to proper build system manually.

{ "cmd": "open", "$file"], "selector": "text.html, source.html, text.xml", }[/quote]

Okay,
but the “open” command only opens the dialog box to open a new document…in my case :wink:

0 Likes

#7

Soory guys,
but if I´m creating an build-file like this:

[code]{
“cmd”: “/Applications/Safari.app”, “$file”],
“selector”: “text.html, source.html, text.xml”

}
[/code]
nothing happend!?
Any hint for me?

0 Likes

#8

handycam originally suggested this was needed

"/Applications/Safari.app/Contents/MacOS/Safari"

Not sure if you’ve tried this already. You also need to then choose this option from Tools/ Build System/ Whatever.

0 Likes

#9

As for OS X, you really want

"cmd": "open", "-a", "Safari", "$file"]

to force Safari to open the file. You can of course substitute Google Chrome or Firefox if you want.

0 Likes

#10

[quote=“svenax”]As for OS X, you really want

"cmd": "open", "-a", "Safari", "$file"]

to force Safari to open the file. You can of course substitute Google Chrome or Firefox if you want.[/quote]

How do I learn to do this? What I’m referring to is how would someone know to try:

"cmd": "open", "-a", "Safari", "$file"]

Is this python code?

Thanks,
Rick

0 Likes

#11

Damm,
I did an OS X update yesterday and know the build didn´t work and no browser obens.
Anybody a clue what I have to (re)do?

The curious thing is, when I open the build-file int sublime itself it opens the browser…

0 Likes

#12

Okay,
I´m one step closer.

If I´m saving a document to my Desktop and execute the build, it works.
It did not work, if I´m saving the document in some subfolders like /projects/web/html.

If checked to set an relative path into my buildfile but I think it´s not right cause it didn´t work :wink:

{ "cmd": "open", "-a", "/Applications/Safari.app", "$file"] }

0 Likes

#13

Okay,
I know the problem.
I´m german…hehe :wink: The prob was that I have a Folder with an mutated vowel.
I´ve renamed it and know it works!

0 Likes

#14

You should just specify the application name as argument to open, not the full path. It will find the application itself using the launch services api.

0 Likes

#15

[quote=“svenax”]As for OS X, you really want

"cmd": "open", "-a", "Safari", "$file"]

to force Safari to open the file. You can of course substitute Google Chrome or Firefox if you want.[/quote]

FWIW, it works as you have it here but with “Google Chrome” it does not work as Chrome inserts “localhost” in the path:

file:///localhost/Users/handycam/Documents/survey1.html
0 Likes

#16

Hi, what if we want to open a localhost page by doing something like this? we can open HTML pages directly but wondering if we could open php pages also by putting local host in URL somehow???

0 Likes

#17
"cmd": "open", "-a", "Safari", "$file"]

I’m using this and the “build results” window is opening up with ‘[Finished]’ as the message. Is there a way to prevent the window from openeing?

0 Likes

#18

Would it be possible to open the file in multiple browsers?
I tried this and it didn’t work, obviously I’m just stabbing in the dark

{
	"cmd": "open", "-a", "Safari", "$file"],
        "cmd": "open", "-a", "Firefox", "$file"]
}
0 Likes

#19

For me it only worked with

{
“cmd”: “c:\Program Files (x86)\Google\Chrome\Application\chrome.exe”, “$file”]
}

I’m new to Sublime Text, and wondering if I’ll ever get used to how complicated things are here … Is Sublime Text for the Unix-hardened only? Or is it going to get simpler someday?

0 Likes

#20

It’s JSON. See the second post in this thread for how to open the build file.

0 Likes