ins*_*get 6 macos applescript window
我正在尝试编写一个可以调整所有打开窗口大小的applescript脚本.为了确保我到达所有窗口,我正在让我的脚本说出应用程序的名称以及该应用程序的打开窗口数.
有趣的是,当我听到所有打开的应用程序的名称时,我的脚本说他们都打开了0个窗口.我该如何解决这个问题?
这是我的代码:
tell application "System Events"
repeat with theProcess in (every process)
if background only of theProcess is false then
if name of theProcess is not "Finder" then
if name of theProcess is "Google Chrome" then
say "Chrome woo hoo"
say (count windows as string)
else
say name of theProcess as string
say (count windows as string)
tell theProcess
repeat with theWindow in windows
say "found a window of"
say (name of theProcess) as string
tell theWindow
click button 2
end tell
end repeat
end tell
end if
end if
end if
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
我使用的是Mac OS X 10.7.5,使用automator 2.2.4来编写/运行这个AppleScript
你必须告诉进程计算窗口.毕竟,这是了解其窗口而非系统事件的过程.
你已告诉进程说出它的名字,例如"将theProcess的名称称为字符串",但是你只使用"说(将窗口计为字符串)"......没有任何进程与之相关.尝试"计算过程的窗口".基本上,你有时会告诉流程,有时你不会告诉流程,有时你告诉流程,即使你已经告诉过程,所以你要做两次.这就是你说"说(进程的名称)为字符串",但该代码在"告诉进程"块中,因此它已被告知进程.
真的,你需要通过你的代码,更准确.提示...如果您想单击窗口中的按钮,则窗口必须位于屏幕的最前面,否则您无法单击它.另一个提示......"名称"已经是一个字符串,因此您不需要将其强制转换为字符串.
顺便说一句,我同意Michael Dautermann对你的帖子的评论......会有一些你无法访问的过程.但随着你的进步,你会发现它.
这是我编写代码的方式.基本上我会在开头使用"tell theProcess"块获取所有变量.然后我可以用这些变量做些事情.我希望有所帮助.请注意,我只是将过程放在最前面,这意味着如果打开多个窗口,它只会单击前窗上的按钮.在单击其按钮之前,您必须添加代码以使每个窗口都显示在前面.祝好运.
tell application "System Events"
repeat with theProcess in processes
if not background only of theProcess then
tell theProcess
set processName to name
set theWindows to windows
end tell
set windowsCount to count of theWindows
if processName is "Google Chrome" then
say "Chrome woo hoo"
say windowsCount as text
else if processName is not "Finder" then
say processName
say windowsCount as text
if windowsCount is greater than 0 then
repeat with theWindow in theWindows
say "found a window of " & processName
tell theProcess
set frontmost to true
tell theWindow
click button 2
end tell
end tell
end repeat
end if
end if
end if
end repeat
end tell
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11439 次 |
| 最近记录: |