You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript to open URL in Safari without titlebar...almost working :-)

Hi guys,

I'm trying to open an URL in Safari with applescript, and i don't want any toolbar in the opened window, actually this code almost works but it open 2 windows as the javascript is executed from document 1

I use Javascript because i dont want to have any modifications of Safari preferences, so when i close it and reopen it should not have the toolbar hidden.

<pre class="jive-pre">tell application "Safari"
activate
tell document 1
do JavaScript ("window.open('http://www.google.com','_blank','titlebar=0');")
end tell
end tell</pre>

Does anybody knows a way to make this work or to open a window without the toolbars ?? I've tried different things but i'm stuck, so any help appreciated.

Thanks by advance,

Max

iMac, MacBook Pro, Mac OS X (10.6.4)

Posted on Aug 30, 2010 8:37 AM

Reply
Question marked as Top-ranking reply

Posted on Aug 30, 2010 3:04 PM

This is about the best you're going to do using JavaScript...

<pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
title="Copy this code and paste it into your Script Editor application.">
tell application "Safari"
activate
set theURL to URL of document 1
set windowID to id of window 1
do JavaScript ("window.open('" & theURL & "','_blank','titlebar=0');") in document 1
close window id windowID
end tell
</pre>

The above script opens a new window with the current document's url and then closes the original window. As far as I've read you cannot get JavaScript to act upon the current window.

Hope this helps at least a little... 🙂
4 replies
Question marked as Top-ranking reply

Aug 30, 2010 3:04 PM in response to max.p

This is about the best you're going to do using JavaScript...

<pre style="width:630px;height:auto;overflow-x:auto;overflow-y:hidden;"
title="Copy this code and paste it into your Script Editor application.">
tell application "Safari"
activate
set theURL to URL of document 1
set windowID to id of window 1
do JavaScript ("window.open('" & theURL & "','_blank','titlebar=0');") in document 1
close window id windowID
end tell
</pre>

The above script opens a new window with the current document's url and then closes the original window. As far as I've read you cannot get JavaScript to act upon the current window.

Hope this helps at least a little... 🙂

Applescript to open URL in Safari without titlebar...almost working :-)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.