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?
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
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.
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.
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).