Isolate front app with Desktop Curtain

One approach to hiding all apps but the active one, using Desktop Curtain

Isolate front app with Desktop Curtain.kmmacros (18.1 KB)

osascript -l JavaScript <<JXA_END 2>/dev/null
var appSE = Application("System Events"),
	appAtFront = appSE.applicationProcesses.where({
		frontmost: true
	})[0];

[
	"Desktop Curtain",
	appAtFront.name()
].forEach(
	function (s) {
		Application(s).activate();
	}
)
JXA_END 
1 Like

Neat. I’ve actually added an action for 7.0 “Conceal All Palettes Until Switch” to get rid of them while watching videos in Safari full screen, but the other monitor is still visible. I had on my todo list an action to blank a monitor, but it did not quite make the cut for 7.0, but Desktop Curtain looks like it’d solve the problem nicely, especially with this macro.

1 Like

Or, perhaps, a toggling version ?

( isolate front app ⇄ show all )

Toggle isolation of front app with Desktop Curtain.kmmacros (18.2 KB)

(function () {
	var c = "Desktop Curtain",
		apps = Application("System Events").applicationProcesses,
		strFrontApp = apps.where({
			frontmost: true
		})[0].name();
			
	if (apps.where({name: c}).length)
		Application(c).quit();
	else
		[
			c,
			strFrontApp
		].forEach(
			function (s) {
				Application(s).activate();
			}
		)
})() 

I don’t quite understand the need for this, since Desktop Curtain can do this on its own. There’s an isolate mode that isolates the frontmost app. Activated I think it does what you do here. Am I mistaken?

‘Need’ would certainly be too strong : - ) Just my solution to a two-step dance I found myself doing each time I first switched DC on – it would ‘hello world’ and at first hide everything, so the second step would be to retrieve the app.

( I personally find it a bit less distracting to be able to fire it up, when I want it, without losing visibility of the app I am typing into )

( Also an experiment in doing something generic – you should, for example, be able to change the app name string to something like “HazeOver”)

Yes, it really seems like there needs to be a way to launch Desktop Curtain in the background without making any changes to the screen, and then ask it to focus the front window, or blank out the screen. I played with it a bit but couldn’t get it to do what I wanted - which is basically just to blank out my second monitor when I’m full screening in Safari on my main monitor.

You guys are right. I just tested it and the way it used to work before it was the way @ComplexPoint scripted it here. Weird. I’ll have to ask Peter (Maurer) if they have changed things here or there.

@ComplexPoint: Nice work on the JavaScript stuff by the way. Been reading the code for a while now. Good to see this is catching on. (Would love to do something more with JXA.)

1 Like

I agree – JXA works very well with Keyboard Maestro automation, and of course Javascript skills pay off on iOS, and the web, and in all the wealth of the npm library and the Atom editor etc too.

For KM macros and plugins, I particularly like:

  • Much more flexible records, which work transparently with JSON.stringify() and JSON.parse()
    • asking a record/object for a list of its keys
    • (for key in record) looping etc
    • simple testing of whether a record/object contains a field/key, etc
  • first class functions, with built in map, reduce and foreach which save scripter time and ink, while helping clarity and structure too
  • the rich library ( just reaching for things like decodeURI() encodeURI() and all the other string (including regex) functions for example, without hacks or dependencies
  • and a lot of little details and flexibilities like being able to set the string of Application(strName) at run-time

Worth moving to Yosemite for, especially now that it’s mature enough for the next iteration of OS X to start : - )

JavaScript for Automation Cookbook
JavaScript for Automation Release Notes

1 Like

I’ve talked with Rob from Many Tricks about this problem here, and they sent me a beta that isolates the front window correctly. This change will make it into the next release. :slight_smile:

Hey Zettt,

Outstanding! Thanks.

-Chris