My Logic Fails

I'm trying to do something very simple. But I do not succeed :triumph:

If the app Scrivener is in front --> hide
If the app Scrivener is not the front app --> show

The problem seems to be: Scrivener can activate a floating window. In this case the window is visible (but not highlighted) even if Scrivener is not the front app. But I don't understand what difference this should make for the if conditions.

I have tried countless variants. This one works fine when „floating window“ is enabled but not otherwise. I am very grateful for your help :grinning:

Worth a try...

tell application "System Events"

	if visible of process "Scrivener" is true then
		set visible of process "Scrivener" to false
	else
		set visible of process "Scrivener" to true
	end if
	
end tell

is this an Apple script? I have no idea about that...

The question is, why does the if condition work only when the window floats? If Scrivener is not the front app, it doesn't matter if you see the window or not.

You just pop it in an Execute AppleScript action.

Try this:

Scrivener - Toggle Hide.kmmacros (18.1 KB)

Might not work, but it's worth a shot. If it doesn't... Are you able to automate disabling the floating window when you hide the app, then re-enabling it when you unhide?

Thanks noisneil, just tried it. Unfortunately, the script does not work either. It hides, but it does not show...
And no, I can't turn it on and off as I want because Scrivener is buggy here.

How did you trigger the script? Did you put it in its own empty macro?

I'm not home right now but can you send a screenshot of the floating window that shows when the app is meant to be hidden?

Gladly. Here the trigger


and here the group

and well, a window is a window. It may or may not float above all other apps
image

"can you send a screenshot of the floating window that shows when the app is meant to be hidden?"

note, if the float function is not switched on, the window appears briefly and disappears again immediately. If I toggle a few times, it eventually settles down.

Yes, my apologies -- I realised I was talking rubbish and tried to delete it before I wasted your time...

and well, a window is a window...

Unfortunately, not all windows are equal --eg if you select "Float on top" for a Stickies note -- and this looks to be one of those cases.

Can you make Scrivener behave the way you want using the Dock, with Ctrl-click and "Hide" or "Show"? If not, this may not be automatable at all.

No problem. I'm glad you give me some of your time :slight_smile: Yes, exactly, Stickies note is a good example.
And yes, Scrivener behaves the way I want using the Dock.

To mention that again: The macro above, works when the window floats, but it doesn't work when the window behaves "normally". Maybe this is a bug in Scrivener.

Nige_S gave me the idea to try the same macro with Stickies note. There it works with floating window or without. Does this mean it's a bug in Scrivener?

FYI, when you want to share a macro image, try this:

Screenshot

It gives you a full length screenshot of the whole macro.

I was just checking you weren't using it as part of your original macro with conditions. It's intended to work as a standalone toggle. Evidently it's not working for you. Hmm....

I have to admit I'm not 100% clear on what the situation is. Correct me if I'm wrong:

You can hide the app, but because a floating window remains visible (even when the app is 'hidden'), you can't unhide the app because KM/Applescript still think it's visible...?

Is there a differentiator in the window titles of the floating window and the main window? That might get us somewhere.

Not necessarily a bug -- there are different types of floating windows, which probably means different behaviours.

I think @noisneil is on the right track. And it might help if there's some way for KM to indicate which "if" branch it's taking each time -- @noisneil, is it possible to drop in AS display dialogs or system beeps (one for true, two for false or something) to troubleshoot?

I generally just watch returned values in Script Debugger for errors.

I've just downloaded the Scrivener trial and set the window to float (Window > Float Window).

Both the applescript above and this basic macro (below) work perfectly, so I don't think I quite understand what the situation is that @Frankb is dealing with yet.

Screenshot

Sorry, the night got in the way.... :slight_smile:

Hmm, noisneil's results are confusing. Then I tried something I didn't think was important. I moved the macro to its own group .... and now it works.

I can't say I understand it, but all that matters is that it works.

noisneil and Nige_S thank you for your help, very kind of you. :slight_smile:

1 Like

Either your group settings were set wrongly or there might have been a conflict with another macro in that group. I suspect it was the former.

Glad you got it working!

Thank you noisneil!