下面是一个使用AppleScript的示例代码,用于查找并设置窗口:
tell application "System Events"
set targetApp to first application process whose frontmost is true
set targetWindow to first window of targetApp
set position of targetWindow to {100, 100} -- 设置窗口位置
set size of targetWindow to {800, 600} -- 设置窗口大小
set bounds of targetWindow to {100, 100, 900, 700} -- 设置窗口位置和大小
set visible of targetWindow to true -- 设置窗口可见性
set index of targetWindow to 1 -- 设置窗口层级
set title of targetWindow to "New Window Title" -- 设置窗口标题
end tell
这段代码使用了System Events
应用程序来查找当前处于前台的应用程序,并获取其第一个窗口。然后,通过设置窗口的position
、size
、bounds
、visible
、index
和title
属性来设置窗口的位置、大小、可见性、层级和标题。
您可以将上述代码保存为一个.applescript文件,然后在AppleScript编辑器中运行它,或者使用其他支持AppleScript的工具来运行它。请注意,该代码可能需要根据您的具体需求进行调整。