1

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
  end repeat
end tell

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.

1 Answer 1

2

This is highly dependant on the app type. I am assuming your app is minimised when you describe it as 'iconified' [which isn't a term I'm familiar with.]

Here are four methods, you could test them one by one, or just leave them all to cycle. Any that fails will not halt the script as it's inside a 'try' block.

tell application "myApp"
    activate
    try
        set miniaturized of windows to false -- most apps
    end try
    try
        set collapsed of windows to false -- Finder
    end try
    try
        tell application "System Events" to tell process "Dock"
            click (last UI element of list 1 where role description is "minimized window dock item")
        end tell
    end try
    try
        reopen -- unminimizes the first minimized window or makes a new default window
    end try
end tell

Credit to Lri on Stack Overflow
Posted as Community Wiki as it's not my answer, only my google-fu;)

My test app, News, only eventually responded to the 4th option.

7
  • Thank you very much. The first one works, and that's the one I'm using. Yes, I meant "miniturized" when I wrote "iconfied". I'll change that wording in my original question.
    – HippoMan
    Oct 9, 2023 at 15:56
  • Very nice initiative, applause!
    – Thinkr
    Oct 9, 2023 at 15:59
  • Glad it worked. Oddly, though Applescript uses 'miniaturised', 'collapsed' etc in scripts, to the rest of the world, including all Apple documentation, the term Minimised is used instead. Sometimes this makes Applescript terms really hard to find :\
    – Tetsujin
    Oct 9, 2023 at 15:59
  • 1
    I find it amusing that more conversation was generated for the discussion about the terms "iconified" versus "minimized" versus "miniturized" than about the technical answer to this question. :):)
    – HippoMan
    Oct 9, 2023 at 17:57
  • 1
    Well, the actual answer turned out to be 'simple' for a given value of 'simple'. The rest was trying to figure out what Apple calls things in public vs in 'dev-speak' ;)
    – Tetsujin
    Oct 9, 2023 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .