Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 11, 2013, 11:58 AM   #1
saha-med
macrumors regular
 
Join Date: Dec 2012
AppleScript opening/tiling two safari windows

Hi, im fairly new to applescript. I want to make a script that will open two Safari windows side by side(tiled) with one window on google.com and another on yahoo.com
So ive been googling various solutions and mixing up different codes to find out a solution. At this point im getting an error with running this applescript, can anyone tell me why?


Thanks in advance

Code:
application "Safari"
	activate
	do JavaScript "window.open('http://www.yahoo.com')" in document 1
	set bounds of window 1 to {160, 80, 980, 700}
	tell application "System Events"
		tell process "Safari"
			click menu item "New Window" of menu "File" of menu bar 1
			set bounds of window 2 to {160, 80, 980, 700}
		end tell
	end tell
end tell
saha-med is offline   0 Reply With Quote
Old Jan 11, 2013, 05:15 PM   #2
andmr
macrumors member
 
Join Date: Aug 2008
Location: NE Florida
Hi,

You might want to try something like this:
Code:
tell application "Safari"
	activate
	open location "http://www.google.com"
	set bounds of window 1 to {10, 123, 513, 457}
	make new document
	open location "http://www.yahoo.com"
	set bounds of window 1 to {513, 123, 1016, 457}
end tell
In this example I set bounds that would work well on my 15'' iMac's screen. Naturally, you'll want to work on your own settings.

Tip: To find the bounds of the frontmost Safari window, use this command in a separate AppleScript Editor window:
Code:
tell application "Safari" to get bounds of window 1
The results can be found in the Editor's Result pane.

Once you have your two Safari windows sized and positioned to your satisfaction, run the "get bounds" command on each window in turn, and then copy and paste the results accordingly into your main script. Good luck.

Script tested using Mac OS 10.4.11

Last edited by andmr; Jan 11, 2013 at 05:44 PM.
andmr is offline   0 Reply With Quote
Old Jan 14, 2013, 07:35 AM   #3
superscape
macrumors member
 
Join Date: Feb 2008
Location: East Riding of Yorkshire, UK
Alternatively...

If you wanted to be a bit more show-offy, you could calculate the coordinates of the window on the fly. For example:

Code:
tell application "Finder"
	--gets the coords of the desktop
	set theScreenSize to bounds of window of desktop
end tell


tell application "Safari"
	activate
	make new document with properties {URL:"http://www.google.com"}
	set bounds of window 1 to {0, 0, (item 3 of theScreenSize) / 2, (item 4 of theScreenSize)} --coords of window are calculated from theScreenSize
	
	make new document with properties {URL:"http://www.yahoo.com"}
	set bounds of window 1 to {(item 3 of theScreenSize) / 2, 0, (item 3 of theScreenSize), (item 4 of theScreenSize)}
	activate
	
end tell

...note that this will only really work well if you use a single monitor - if you have a second monitor then things get fiddly!
superscape is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:39 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC