Utility that locks full screen app

james948

macrumors 6502
Original poster
Nov 17, 2004
346
18
Hi there,
I'm looking for a focus/concentration app that locks me to one screen for a period of time.

Too often do I switch from my writing app of choice to "check" something on the web only to discover, half an hour later, I'm fifteen levels into wikipedia with no idea what I came on to search for.

I'd like to prevent app switching (without a password) so I can remind myself not to switch and to deter me from doing it.

Sort of like Guided Access on iPhone.

Thus far, I can't find anything apart from people advising to make a new managed account.

Any ideas?
Thanks
James
 

0d085d

macrumors regular
Apr 23, 2015
154
12
Applescript can do this:

Code:
set releasePassword to "bing"

on waitForFocusLost(appName)
	tell application appName
		repeat
			if not frontmost then
				return
			end if
		end repeat
	end tell
end waitForFocusLost

set lockedApp to text returned of (display dialog "Which application do you want to lock?" default answer "Safari")
tell application lockedApp
	activate
	set frontmost to true
end tell
delay 1
repeat
	waitForFocusLost(lockedApp)
	tell application lockedApp
		display dialog "Enter the password to leave this application" default answer "" buttons {"Never mind", "Release!"} default button "Never mind"
		if button returned of result is not "Never mind" then
			set userPass to text returned of result
			if userPass is equal to releasePassword then
				return
			end if
			display dialog "Wrong password!"
		end if
		activate
	end tell
end repeat
Use Script Editor to File->Export... the script as an application after you've set your password on the first line. You can then run the application to lock yourself into a particular app.

Note:
  1. Application names are case insensitive. If you get it wrong it'll ask you to choose from a list.
  2. The "Never mind" button is deliberately the default so that you have to deliberately use the mouse to release yourself.
 

james948

macrumors 6502
Original poster
Nov 17, 2004
346
18
WOW! Did you just write this? This is superb!

----------

Any ideas what this means?

Scrivener got an error: Can’t set frontmost to true. (-10006)
 

0d085d

macrumors regular
Apr 23, 2015
154
12
WOW! Did you just write this? This is superb!
Haha, thanks!

Any ideas what this means?

Scrivener got an error: Can’t set frontmost to true. (-10006)
Whoops, looks like frontmost doesn't work in non-Apple apps. Never mind - try this instead:

Code:
set releasePassword to "bing"

on waitForFocusState(appName, triggerState)
	tell application appName
		repeat
			if frontmost is equal to triggerState then
				return
			end if
		end repeat
	end tell
end waitForFocusState

set lockedApp to text returned of (display dialog "Which application do you want to lock?" default answer "Scrivener")
tell application lockedApp to activate
waitForFocusState(lockedApp, true)
repeat
	waitForFocusState(lockedApp, false)
	tell application lockedApp
		activate
		display dialog "Enter the password to leave this application" default answer "" buttons {"Never mind", "Release!"} default button "Never mind"
		if button returned of result is not "Never mind" then
			set userPass to text returned of result
			if userPass is equal to releasePassword then
				return
			end if
			display dialog "Wrong password!"
		end if
		activate
	end tell
end repeat
 

james948

macrumors 6502
Original poster
Nov 17, 2004
346
18
This is great! Thanks so much.

To be honest, if it had a few settings and didn't let me change spaces at all, I'd have no problem paying £1.99 for it! You should slap it in the app store!
 

0d085d

macrumors regular
Apr 23, 2015
154
12
You should slap it in the app store!
Way too much box-ticking required. Compliment appreciated nonetheless! Happy to have helped.

... and didn't let me change spaces at all...
Ah, assumed it already did this. If you're not using any external displays, a quick "delay" fixes that:

Code:
set releasePassword to "bing"

on waitForFocusState(appName, triggerState)
	tell application appName
		repeat
			if frontmost is equal to triggerState then
				return
			end if
		end repeat
	end tell
end waitForFocusState

set lockedApp to text returned of (display dialog "Which application do you want to lock?" default answer "Scrivener")
tell application lockedApp to activate
waitForFocusState(lockedApp, true)
repeat
	waitForFocusState(lockedApp, false)
	tell application lockedApp
		activate
		delay 0.3
		display dialog "Enter the password to leave this application" default answer "" buttons {"Never mind", "Release!"} default button "Never mind"
		if button returned of result is not "Never mind" then
			set userPass to text returned of result
			if userPass is equal to releasePassword then
				return
			end if
			display dialog "Wrong password!"
		end if
		activate
	end tell
end repeat
 

trainwrecka

macrumors 6502
Apr 24, 2007
393
322
Earth
Too often do I switch from my writing app of choice to "check" something on the web only to discover, half an hour later, I'm fifteen levels into wikipedia with no idea what I came on to search for.
There was a great app called "Concentrate" that allowed you to enter a zone that only allowed for access to certain apps and certain websites depending on the task you wanted to accomplish. The newer versions of OSX killed its functionality.

As an alternative - and since most time waste comes from the web - I use WasteNoTime extension in Safari. Works great.
 

frbrn

macrumors newbie
Nov 9, 2015
1
0
This is the perfect focus app, just genius. I was initially confused at how the app seemed to know I wanted to focus on Scrivener, esp as it's such a niche app, and then I noticed the default in the script — good luck with your writing project(s)!