I'm running macOS 11.7.10.
I have an app which I always want to be running, and I have successfully caused it to start up whenever I log in. Often, I minimize this running app, and its Dock icon then shows it as running.
I want to use osascript to cause this app to open when it's running but minimized. In other words, I want AppleScript to perform the same function that gets performed if I click once on this already-running app's dock icon.
I tried the following AppleScript code, but it only opens the app if it's not already running:
set appname to "name of my app"
tell application appname to launch
tell application "System Events"
repeat until visible of process appname is false
set visible of process appname to false
What is the proper AppleScript code for opening the app if it's already running but minimized in the dock?
Thank you very much in advance.