Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 7, 2011, 02:13 PM   #1
drakino
macrumors regular
 
Join Date: Feb 2006
Applescript, dual monitors, and full screen Chrome

I'm working on an Applescript to manage a Mac Mini attached to two (soon to be three via a USB video adaptor) TV screens that display various web based stats views.

Chrome was picked for this due to it's full screen mode that removes all the browser UI, along with the Applescript support that was added in a few versions back.

The specific problem I'm having is getting both Chrome windows to go full screen. I can get one to work, but any attempts to bring the second window forward and make it full screen fail. Usually the first window just exits full screen.

Here is one of my iterations at attempting this, if anyone has any ideas, this would be appreciated. This may be hard to test if you don't have two monitors.

(I'm including a slightly cut down version, but including some useful code here if someone else is attempting similar. The code below will open Chrome, loading two tabs in the first window, and one tab in the second. It also attempts to reposition the browsers so one is on the left TV {0,0,1920,1080} and the second is on the right TV {2560, 0, 5120, 1080}. I chose not to auto detect both monitors and position accordingly, as resolution and arrangement won't be changing once this is all set up. The script does assume the monitor on the left has the Mac menu bar to flag it as the primary screen)

Code:
tell application "Google Chrome"
	tell window 1
		set URL of active tab to "http://apple.com"
		repeat while loading of active tab
			delay 0.1
		end repeat
		set myTab to make new tab at end of tabs with properties {URL:"http://trailers.apple.com"}
		repeat while loading of active tab
			delay 0.1
		end repeat
	end tell
end tell

tell first window of application "Google Chrome" to set bounds to {0, 0, 1920, 1080}

tell application "Google Chrome"
	set aWin2 to make new window with properties {mode:"normal"}
	tell window 1
		set URL of active tab to "http://me.com"
		repeat while loading of active tab
			delay 0.1
		end repeat
	end tell
end tell

tell first window of application "Google Chrome" to set bounds to {2560, 0, 5120, 1080}

-- Bring Chrome to the front and full screen both windows
tell application "Google Chrome"
	activate
end tell
tell application "System Events" to keystroke "f" using {command down, shift down}
delay 3
tell application "Google Chrome"
	set index of window 2 to 1
end tell
tell application "System Events" to keystroke "f" using {command down, shift down}
drakino is offline   0 Reply With Quote
Old May 7, 2011, 11:53 PM   #2
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
I think you've encountered a limitation of Chrome. It does kind of make sense that only one window would be allowed to be "full"-screen at a time.

An idea: Have a single Chrome UI-less window stretch across all the screens. Load a local HTML file that loads the desired pages into frames positioned so that there's one frame per screen.
jiminaus is offline   0 Reply With Quote
Old May 8, 2011, 01:14 AM   #3
drakino
Thread Starter
macrumors regular
 
Join Date: Feb 2006
It doesn't appear to be a Chrome limitation, as I can manually make two windows go full screen on different monitors. The way I did it manually was to open two windows, move one fully to the second monitor, type Command-Shift F, then click once on the window not in fullscreen and press the same key combo. Both remain in full screen mode.

If I can't get the Applescript method working in the same way, I'll look into implementing your idea. Hadn't really thought about using frames, hopefully that doesn't break some of the javascript in use on some of the web pages to be displayed.
drakino is offline   0 Reply With Quote
Old May 8, 2011, 04:28 AM   #4
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Okay. I don't know AppleScript, but I got the following to work.

Code:
tell application "Google Chrome"
	activate
	set aWin1 to make new window with properties {mode:"normal", bounds:{-1000, 0, -500, 500}}
	tell aWin1
		set URL of first tab to "http://apple.com"
		set tab2 to make new tab at end of tabs with properties {URL:"http://trailers.apple.com"}
	end tell
end tell
tell application "System Events" to keystroke "f" using {command down, shift down}

delay 1

tell application "Google Chrome"
	set aWin2 to make new window with properties {mode:"normal", bounds:{0, 0, 500, 500}}
	tell aWin2
		set URL of first tab to "http://me.com"
	end tell
end tell
tell application "System Events" to keystroke "f" using {command down, shift down}
There's many more edits to your code then were necessary, I took the opportunity to learn some AppleScript.

The idea is to setup one window, make it fullscreen, and then go into setting up the second window and making it fullscreen.

The delay is critical. If I tried to make the second window fullscreen while the first window is still in the process of animating into fullscreen, it would abort the fullscreen mode of the first window.

Also I needed to setup the window on secondary screen before setting up the window on the primary screen. If I did the other way around, the menu bar and dock showed.

(BTW I had to muck around with your windows' bounds because my monitors are in a different configuration to yours).


EDIT: This is also works if you need the pages to be loaded before Chrome is activated. But it will break if the titles of the individual windows is not unique.
Code:
tell application "Google Chrome"
	set windowOnSecondaryScreen to make new window with properties {mode:"normal", bounds:{-1000, 0, -500, 500}}
	tell windowOnSecondaryScreen
		set tab1 to first tab
		set tab1's URL to "http://apple.com"
		set tab2 to make new tab at end of tabs with properties {URL:"http://www.google.com"}
	end tell
	
	set windowOnPrimaryScreen to make new window with properties {mode:"normal", bounds:{0, 0, 500, 500}}
	tell windowOnPrimaryScreen
		set tab3 to first tab
		set tab3's URL to "http://me.com"
	end tell
	
	repeat while loading of tab1 or loading of tab2 or loading of tab3
		delay 0.1
	end repeat
	
	set titleOfWindowOnPrimaryScreen to windowOnPrimaryScreen's title
	set titleOfWindowOnSecondaryScreen to windowOnSecondaryScreen's title
	
	activate
end tell

tell application "System Events"
	set chromeWindowMenu to first menu of menu bar item "Window" of first menu bar of process "Google Chrome"
	tell process "Google Chrome" to click menu item titleOfWindowOnSecondaryScreen of chromeWindowMenu
	keystroke "f" using {command down, shift down}
	delay 1
	tell process "Google Chrome" to click menu item titleOfWindowOnPrimaryScreen of chromeWindowMenu
	keystroke "f" using {command down, shift down}
end tell

Last edited by jiminaus; May 8, 2011 at 05:23 AM. Reason: Add 2nd code example
jiminaus is offline   0 Reply With Quote
Old May 9, 2011, 02:05 PM   #5
drakino
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Much appreciated jiminaus. I ended up using code from your second sample, and injected a few other delays due to some problems that cropped up from time to time once it was deployed to the Mini.

I'm going to let it run for this week and see how it handles it. Due to some memory leaks in the web pages being displayed, I'm running the overall script in a big loop that quits the browser from time to time. Once I've hardened the script a bit more, I'll post it here, as it is working well for a TV kiosk type setup.
drakino is offline   0 Reply With Quote
Old Sep 16, 2011, 06:48 PM   #6
drakino
Thread Starter
macrumors regular
 
Join Date: Feb 2006
I've still been making tweaks to this script (and even expanded it to support 3 screens). Some stability issues persist, but I'm hoping a rewrite here soon will fix some outstanding issues. Once I verify this planned rewrite, I'll post it here.

In the interim, anyone interested in using Chrome with applescript like this should star the following enhancement request. http://code.google.com/p/chromium/is...etail?id=96915

And if the planned system is going to be running Lion, and multiple monitors, staring this issue would be appreciated.
http://code.google.com/p/chromium/is...etail?id=96913
drakino is offline   0 Reply With Quote
Old Nov 7, 2011, 07:49 PM   #7
mikeryan
macrumors newbie
 
Join Date: Dec 2002
I'm interested in doing something similar. Glad to find this post.

When I followed the link you gave to Issue 96915, Feature request: Applescript call to enter full screen and presentation mode, I noticed that it indicates the status is Fixed and Closed on Oct 25.

Does that mean it should work now? Or, will it be included in the next release of Chrome? How do you tell?
mikeryan is offline   0 Reply With Quote
Old Nov 7, 2011, 09:38 PM   #8
drakino
Thread Starter
macrumors regular
 
Join Date: Feb 2006
Quote:
Originally Posted by mikeryan View Post
When I followed the link you gave to Issue 96915, Feature request: Applescript call to enter full screen and presentation mode, I noticed that it indicates the status is Fixed and Closed on Oct 25.

Does that mean it should work now? Or, will it be included in the next release of Chrome? How do you tell?
It's checked into the trunk, and I believe it's lined up with Chrome 17, possibly 18. Their version tracking is a mess to figure out as an outsider.

The downside for me is that due to them refusing to address bug 96913, I've had to hold back the Chrome release on our internal Lion systems to Chrome 13. Updating to 14 breaks the systems with multiple monitors, and Google Chrome developers believe Apple has to fix it. Stuck between two stubborn dev teams I suppose.

I have done some investigation into swapping over to Firefox, but haven't committed to that path yet. The TVs is a "free time" type project at work, and my department has been busy with other more important things. Once we broke the Chrome autoupdate, we found the TVs to be much more stable, since some random update won't be auto applied and break things.
drakino is offline   0 Reply With Quote
Old Aug 2, 2012, 03:25 AM   #9
gregor.hoch
macrumors member
 
Join Date: Apr 2011
Anything new about this? Mountain Lion did NOT solve the problem...
What are your solutions?
gregor.hoch is offline   0 Reply With Quote

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

Tags
applescript, chrome, fullscreen, multiple monitor

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Audio out of Sync when Full Screen on Chrome celticfc482 MacBook Pro 9 Mar 6, 2014 03:04 PM
Retina Macbook Pro with Chrome+youtube full screen Dreamer2go MacBook Pro 5 Dec 3, 2013 10:39 PM
Is it possible to multi-task in full-screen across two monitors? ivbaseball06 iMac 2 Jan 5, 2013 12:19 AM
Apple Movie Trailers in Full Screen via Chrome? joejoejoe OS X 10.8 Mountain Lion 3 Sep 28, 2012 11:14 PM
Full screen mode (Lion10.7) with Screen Sharing with Multiple Monitors? deansawyer Mac Applications and Mac App Store 2 Aug 23, 2012 06:33 PM

Forum Jump

All times are GMT -5. The time now is 07:19 AM.

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

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