Process AppleScript:从应用程序隐藏/获取进程名称

Process AppleScript:从应用程序隐藏/获取进程名称,process,applescript,hide,pid,Process,Applescript,Hide,Pid,我想隐藏最前面的应用程序。 我知道您可以使用以下语法隐藏进程: tell application "System Events" set visible of process "..." to false end tell 我知道如何获得最前端的应用程序: (path to frontmost application as string) 但是我如何将这两个命令连接在一起呢 这是行不通的: tell application "System Events" set visibl

我想隐藏最前面的应用程序。 我知道您可以使用以下语法隐藏进程:

tell application "System Events"
    set visible of process "..." to false
end tell
我知道如何获得最前端的应用程序:

(path to frontmost application as string)
但是我如何将这两个命令连接在一起呢

这是行不通的:

tell application "System Events"
    set visible of process (path to frontmost application as string) to false
end tell
试试这个

tell application "System Events"
    set frontProcess to first process whose frontmost is true
    set visible of frontProcess to false
end tell

您必须小心,因为在某些情况下,当您运行脚本时,脚本是最前面的,因此您可能最终会隐藏脚本而不是目标应用程序。我检查最前面进程的名称,如果该名称与脚本或“applescript runner”的名称匹配,那么您需要隐藏该名称,然后再次运行该命令,您将实际获得所针对的应用程序。这很棘手。

因为如果按Cmd-H,大多数应用程序都会隐藏,所以您也可能会这样做

tell app "System Events" to keystroke "h" using command down

Chuck,这甚至都没有试图回答OP的问题,所以最好把它作为一个评论而不是答案发布。我认为这是一个有效的答案。这个想法可能与Tyilo的想法完全不同,但应该是可行的。