Determining Whether an Application Process is Hidden
MacOS MacOS X Windows

This assumes you have a good understanding of what a process is and how to identify a process you'd like to manipulate . If you don’t, take a look at tip proc005 - Understanding Processes before continuing.

The Macintosh portion of this code is implemented in AppleScript, and the Windows portion is implemented using the PrcView* command line utility, and assumes that you have put the pv.exe application in the same directory as your standalone (i.e. the default "directory").

function IsHidden pProcessName
  switch (the platform)
  case "MacOS"
    put "tell application" && q("Finder") && cr & \
        "set tResult to the visible of process " & q(pProcessName) & cr & \
        "return tResult" & cr & \
        "end tell" into tScript
    do tScript as AppleScript
    put the result into tHidden
    if tHidden = "execution error" then return "Process not found."
    break
  case "Win32"
    set the hideConsoleWindows to true
    put shell("pv -q") into tProcList
    if matchText(cr&tProcList&cr,"\n" & pProcessName & tab) is false then
      return "Process not found."
    else
      put shell("pv -w -q") into tProcList
      put "" into tProcesses
      put true into tHidden
      repeat for each line tProc in tProcList
        put item 1 of tProc into tProc
        if tProc = pProcessName then
          put false into tHidden
          exit repeat
        end if
      end repeat
    end if
    break
  end switch
  return tHidden
end IsHidden

function q what
  return quote & what & quote
end q
Note that both “background-only” processes as well as processes that have been hidden by choosing Hide <appname> are considered hidden to the Finder. In Windows, applications that do not have a visible window are considered hidden; there is no user-accessible "hide" command as there is in Macintosh.

* PrcView is a command line utility developed by Igor Nys, and can be downloaded at http://www.prcview.com/. PrcView is free for personal use or to be distributed with freeware applications; for shareware or commercial use, please contact Igor. Licensing costs are very reasonable, and he is very willing to work with you to make it worth your while to use his application.

Posted 12/26/02 by Ken Ray