I am trying to make an automator workflow that opens an app if it's not already open, or closes the app if it is open. I need a script that will run the QuickShade.app
when I tap the button to run the script in my TouchBar it will pull up a dialogue box with the option of Cancel and Toggle.
when I press toggle, a script is to run that does the following
If Quickshade.app is not running --> Open app --> end script
Else
If QuickShade.app is running --> Quit App --> End Script
The issue here is the code I am putting in is not working to check if the app is open, or not, and it won't swap the states, or it swaps the states twice and crashes, or there's a syntax error and the script doesn't run.
I have given up and hope someone might be able to help.
I apologise if this is not making sense. It makes sense in my head, but probably not on paper.
What I have tried is below
Replace 'App Name' with App path
First Attempt
on run {input, parameters}
tell application "System Events" to set visible of process "<app name>" to not (visible of process "<app name>")
end run
no error, won't run
Attempt 2
set appName to "<app name>"
set isRunning to false
tell application "System Events"
set isRunning to count (every process whose name is appName) > 0
end tell
if isRunning then
tell application appName to quit
else
tell application appName to activate
end if
tell application "System Events" to set visible of process "Script Editor" to false
Can't understand what the parameters/input is and I don't know what to put here.
Attempt 3
set appName to "<app name>"
set isRunning to false
tell application "System Events"
set isRunning to (count (every process whose name is appName)) > 0
end tell
if isRunning then
tell application appName to quit
else
tell application appName to activate
end if
tell application "System Events" to set visible of process "Script Editor" to false
it can't get the application
set isRunning to (count (every process whose name is appName)) > 0. The{input, parameters}arguments are a list of input items from the previous Automator action and a record of the current action's parameters.runningproperty of anapplication, e.g.application "QuickShade" is running(which returnstrueif it is running, andfalseotherwise).runningproperty. Shorter and more reliable.)