开发者

AppleScript: Hide/Get process name from app

开发者 https://www.devze.com 2023-03-03 17:04 出处:网络
I want to hide the frontmost app. I know you can hide a process using the syntax: tell application \"System Events\"

I want to hide the frontmost app. I know you can hide a process using the syntax:

tell application "System Events"
    set visible of process "..." to开发者_运维问答 false
end tell

and i know how to get the frontmost app:

(path to frontmost application as string)

But how do I bridge the two commands together?

This will not work:

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


Try this.

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

You have to be careful because in some ways when you run the script, the script is frontmost so you may just end up hiding the script instead of the application you were targeting. I check the name of the frontmost process, and if that matches the name of the script or "applescript runner" then you need to hide that, then run the command again and you'll actually get the application you were targeting. It's tricky.


Since most applications will hide if you press Cmd-H, you could also probably go that route.

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

精彩评论

暂无评论...
验证码 换一张
取 消