Jump to content

Apple Script to check/open app on the same desktop


Recommended Posts

Hi, I'm trying to create a workflow that allows me to open a new window of Things app on the active macOS desktop (or space, whatever it is called) if it is not already open. If the window is already open, I want to make it the active/foremost app. If I switch to another desktop/space, this feature applies there separately. 

 

I could only write this AS which opens a new window every time. Could anyone please help me out?

 

tell application id "com.culturedcode.ThingsMac"
    make new window
end tell

 

Link to comment

I'm afraid I can't give you a complete answer but part of the answer may be in using:

  • an Automation Task Is App Running linked to a Conditional Action (depending upon whether or not the app is running);
  • if the app is running an Automation Task Identify Frontmost App linked to another Conditional Action…

then (I suspect) linked to some AppleScript—one script for if the app is the frontmost app and one for it it is not. I think part of the AppleScript solution is to use the activate command for the app (which should bring the app to the front, launching it if necessary).

 

Sorry not to have provided a complete solution but I hope this is at least of some help!

 

Stephen

 

 

Edited by Stephen_C
Fix typo
Link to comment

You should ask about this in the Things forums/help, since it’s entirely related to it and its AppleScript support; each application implements their own dictionary. I don’t use Things so I can’t guarantee this will work as it, but the logic is:

 

tell application id "com.culturedcode.ThingsMac"
  if (count windows) < 1 then
    make new window
  else
    activate
  end if
end tell

 

Don’t count on programmatic access to different Desktops and the like, though. Apple doesn’t provide a public API for it, solutions online rely on GUI automation.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...