Toggle Fullscreen Kiosk Mode in Safari with AppleScript

safari-icon.tiffOnline video sites, while for the most part not nearly as crisp and certainly not as convenient as a local video, can provide a quick fix if you’ve a few minutes to spare and don’t want to crack open that Dostoevsky novel. But I’m not talking about YouTube or Vimeo here, but rather those sites of questionable legality of which the majority stream copyrighted material. I’m not really recommending these sites - but try alluc.org for an example of what I mean.

Most of these videos will play in an browser based player that can’t enter true full screen mode:

vid-in-safari.jpg

There are, however, a few things you can do to enhance the experience.

safari-view-menu.pngFirst off, you can resize the window by dragging it to the full size of your screen (a no brainer). But you can also hide many of Safari’s buttons and bars - Bookmarks Bar, Status Bar, Tab Bar and Toolbar by selecting their relevant ‘Hide’ options from under Safari’s View menu. After you’ve done all this, you should have a reasonably pseudo-kiosked Safari perfect for viewing online videos fullscreen.

The only problem with this solution is the manual involvement required to bring it about, as well as to return your browser to its normal way of being. In reality, though, this isn’t a problem - it’s a great opportunity to fire up Script Editor and automate the task!

Copy and paste the below code into Script Editor (Applications/AppleScript/Script Editor). Run it once to set Safari to full screen kiosk mode. Run it again to shrink Safari and bring back your tool bars.

tell application "Safari"
	activate
	if bounds of window 1 is not equal to {0, 22, 1440, 900} then
		tell application "System Events"
			keystroke "b" using {command down, shift down}
			keystroke "|" using command down
		end tell
		set bounds of window 1 to {0, 22, 1440, 900}
	else
		tell application "System Events"
			keystroke "b" using {command down, shift down}
			keystroke "|" using command down
		end tell
		set bounds of window 1 to {160, 80, 980, 700}
	end if
end tell

A few caveats about this script. First, it’s a GUI (graphic user interface) script, and consequently requires Assistive Access to be turned on. To do so, open up AppleScript Utility (in Applications/ AppleScript/ AppleScript Utility) and check ‘Enable GUI Scripting.’ Enabling this feature allows your AppleScripts to manipulate the keyboard, which in turn lets you access functions for applications that don’t support Apple Events but do have menu bar items or other clickable items (like hide/show Tool Bar, for instance).

Secondly, in its above form the script will only hide/show the Toolbar and the Bookmarks Bar - which are the only two tool bars that I personally keep visible during normal use. If you are a Status Bar lover, add the code

keystroke "/" using command down

between each of the System Events tell blocks. For the Tab Bar, change “/” to “t” and repeat this process.

Lastly, the script is set for use with a 15″ MacBook Pro. If you use a MacBook, change instances of 1440 and 900 to 1280 and 800 respectively. 17″ MacBook Pro users should do the same with the values 1680 and 1050.

I hope this script helps you get the most out of your browser. As always, if you have any questions, suggestions or problems with the script, let me know in the comments.

* * *

2 Responses to Toggle Fullscreen Kiosk Mode in Safari with AppleScript

  1. I love the idea of your comment box being labeled “Think Different?”. Genius!

    Just had to say,
    MacTipper
    My Mac-Tipping Blog

  2. Thanks MacTipper! Truthfully, I was hesitant to add it, fearing to be unsubtle. Your comment is a vote of confidence.

    MacTipper has so many useful hints. I am already a subscriber to the RSS feed!

Think different?