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 regular
 
Join Date: Feb 2008
Location: 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

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: Tiling windows? chris200x9 Mac Applications and Mac App Store 4 May 21, 2014 08:49 AM
Opening a file in AppleScript Chemical666 Mac Programming 2 May 7, 2014 06:47 PM
Choose application dialog opening when not needed in my Applescript hary536 Mac Programming 2 Nov 15, 2013 01:14 PM
Opening URL from Mail overwrites Safari tab instead of opening new tab hscottm OS X 10.8 Mountain Lion 3 Nov 21, 2012 02:02 PM
Stop Safari opening previous webpage on opening safari mds1256 Mac Applications and Mac App Store 0 Jun 27, 2012 02:50 PM

Forum Jump

All times are GMT -5. The time now is 06:32 AM.

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

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