繁体   English   中英

如何在 Mac AppleScript 中从 PID 获取要调用的应用程序名称

[英]How to get Application Name To Call from PID in Mac AppleScript

有一个脚本可以让您在 mac 中调整任何应用程序的大小。 这是代码:

set theApp to "Application Name" 
set appHeight to 1080
set appWidth to 1920

    tell application "Finder"
    set screenResolution to bounds of window of desktop
end tell

set screenWidth to item 3 of screenResolution
set screenHeight to item 4 of screenResolution

tell application theApp
      activate
      reopen
      set yAxis to (screenHeight - appHeight) / 2 as integer
      set xAxis to (screenWidth - appWidth) / 2 as integer
      set the bounds of the first window to {xAxis, yAxis, appWidth + xAxis, appHeight + yAxis}
      end tell

我想更改启动器打开的 java 应用程序的大小。 当我插入任何应用程序的名称时,它就可以工作。 但是,当我插入要调整大小的应用程序的名称时,它不起作用。 我知道要调整大小的应用程序的进程 ID。 有没有办法可以将这一行set theApp to "Application Name"以使用 PID 而不是应用程序名称? 谢谢。

并非所有应用程序都可以编写AppleScript脚本,有些应用程序不支持bounds属性,它们使用position属性size属性 此外,有时您需要position系统事件并调整应用程序的window大小

我使用在FastScripts中分配的键盘快捷键和以下示例AppleScript代码来自动调整最前面的应用程序的window 您可以调整代码以满足您的需求。

如果最前面应用程序不能使用bounds属性,它会默默地出错,然后系统事件会这样做。

tell application "System Events"
    set frontmostProcess to name of process 1 whose frontmost is true
end tell

try
    tell application frontmostProcess
        set bounds of window 1 to {0, 22, 1136, 844}
    end tell
on error
    tell application "System Events" to tell application process frontmostProcess
        set position of window 1 to {0, 22}
        set size of window 1 to {1136, 822}
    end tell
end try

注意:我不隶属于 FastScript 的开发者,只是一个满意的用户。 前十个键盘快捷键也是免费的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM