Move a window to current desktop

Hi,

I am trying to design an action which opens a finder window via shortcut. It looks following now:

If All Conditions Met
Application ‘Finder’ is running but not at the front
Execute the Following Actions:
Activate Finder
Reopen initial windows.
Notify on failure.

However, the problem is that finder could already be open on another desktop. In that case, nothing happens. Is there a way to let KM check if the window is open on another desktop and move it as a frontmost application to the current desktop?

I have a related post here: (OSX 10.11 (El Capitan) split view ? (I haven't succeeded yet)

It detects a window position, and proceeds from there. This would definitely return failure, if there’s no window.

Hey SH,

Spaces doesn’t have an open API, so there’s not a lot Peter can do to manage them.

In your case an Execute an AppleScript action will do the trick…

------------------------------------------------------------
# Your folder.
set theFolder to alias ((path to downloads folder as text) & "test:")
------------------------------------------------------------
tell application "System Events"
  if quit delay ≠ 0 then set quit delay to 0
  tell application process "Finder"
    if its visible is false then set its visible to true
    set frontmost to true
  end tell
end tell
tell application "Finder" to open theFolder
------------------------------------------------------------

This should open the designated folder in the current Space’s Finder, but if the folder is already open in another Space it will switch to it.

Unfortunately you cannot differentiate Finder windows in different spaces, but you can detect whether the folder is in fact open.

tell application "Finder"
  set winList to windows whose name is "Downloads"
  if length of winList > 0 then
    # Do something.
  else
    # Do something else.
  end if
end tell

-Chris

Thanks CareyB, ccstone,

it seems to be a little bit more problematic than I thought…

Please clarify! Do you want to specify a Desktop, as I do, or a Space?

My error, more like a space. Desktop is not that difficult to handle… My problem: it seems, like it involves a lot of hacking up to the point, where it saves you no time at all. Which is, in my opinion, the main purpose of scripting.

What’s the difference? It seems that Apple uses these interchangeably.

Perhaps this will help: https://support.apple.com/kb/PH18757?locale=en_CA

I notice that if I press the F3 key on my two monitor setup, my main monitor is labelled ‘Desktop 1’ and my second monitor is labelled ‘Desktop 2’. I infer from this that every ‘Space’ has it’s own Desktop(s). I think we can further infer that Desktops and Spaces are not the same thing.

KM/OS X has a single coordinate system for a ‘desktop’ which spans multiple monitors. You can calculate which window the monitor is on. This might be a good place to start: https://wiki.keyboardmaestro.com/Conditions

See Chrome New Window on Specified Desktop for a related macro, whose pieces might give you hints for accomplishing what you want. You probably can’t get exactly what you want, but you might be able to put together a pragmatic compromise.

I answered my question about the difference between spaces and desktops in an extensive separate post.

If you are talking about multiple monitors, Keyboard Maestro can help you position your windows across all of the monitors (ie, across the desktop).

If you are talking about multiple spaces, then there is no API for that and the only solution is UI hacks (like typing the keystrokes for the Spaces system).